Skip to content

Commit c9638a1

Browse files
authored
Help Coverty avoid generating a false positive. (#4817)
* Change variable name `it` to `curr_overl` to improve readability, add `assert()` in the only place where `curr_overl` could become `nullptr`. * Move the `assert()` to where Coverty generates a false positive. * variable name as suggested by @henryiii
1 parent db412e6 commit c9638a1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

include/pybind11/pybind11.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ class cpp_function : public function {
719719
/* Iterator over the list of potentially admissible overloads */
720720
const function_record *overloads = reinterpret_cast<function_record *>(
721721
PyCapsule_GetPointer(self, get_function_record_capsule_name())),
722-
*it = overloads;
722+
*current_overload = overloads;
723723
assert(overloads != nullptr);
724724

725725
/* Need to know how many arguments + keyword arguments there are to pick the right
@@ -757,9 +757,10 @@ class cpp_function : public function {
757757
std::vector<function_call> second_pass;
758758

759759
// However, if there are no overloads, we can just skip the no-convert pass entirely
760-
const bool overloaded = it != nullptr && it->next != nullptr;
760+
const bool overloaded
761+
= current_overload != nullptr && current_overload->next != nullptr;
761762

762-
for (; it != nullptr; it = it->next) {
763+
for (; current_overload != nullptr; current_overload = current_overload->next) {
763764

764765
/* For each overload:
765766
1. Copy all positional arguments we were given, also checking to make sure that
@@ -780,7 +781,7 @@ class cpp_function : public function {
780781
a result other than PYBIND11_TRY_NEXT_OVERLOAD.
781782
*/
782783

783-
const function_record &func = *it;
784+
const function_record &func = *current_overload;
784785
size_t num_args = func.nargs; // Number of positional arguments that we need
785786
if (func.has_args) {
786787
--num_args; // (but don't count py::args
@@ -1018,10 +1019,10 @@ class cpp_function : public function {
10181019
}
10191020

10201021
if (result.ptr() != PYBIND11_TRY_NEXT_OVERLOAD) {
1021-
// The error reporting logic below expects 'it' to be valid, as it would be
1022-
// if we'd encountered this failure in the first-pass loop.
1022+
// The error reporting logic below expects 'current_overload' to be valid,
1023+
// as it would be if we'd encountered this failure in the first-pass loop.
10231024
if (!result) {
1024-
it = &call.func;
1025+
current_overload = &call.func;
10251026
}
10261027
break;
10271028
}
@@ -1168,7 +1169,8 @@ class cpp_function : public function {
11681169
if (!result) {
11691170
std::string msg = "Unable to convert function return value to a "
11701171
"Python type! The signature was\n\t";
1171-
msg += it->signature;
1172+
assert(current_overload != nullptr);
1173+
msg += current_overload->signature;
11721174
append_note_if_missing_header_is_suspected(msg);
11731175
// Attach additional error info to the exception if supported
11741176
if (PyErr_Occurred()) {

0 commit comments

Comments
 (0)