Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const
auto tokvalue_it = std::find_if(expr->astOperand1()->values().begin(),
expr->astOperand1()->values().end(),
std::mem_fn(&ValueFlow::Value::isTokValue));
if (tokvalue_it == expr->astOperand1()->values().end()) {
if (tokvalue_it == expr->astOperand1()->values().end() || !tokvalue_it->isKnown()) {
return unknown;
}
tokvalue = tokvalue_it->tokvalue;
Expand Down
9 changes: 9 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,15 @@ class TestBufferOverrun : public TestFixture {
" snprintf(str, sizeof(str), \"%hu\", port);\n"
"}", settings0, "test.c");
ASSERT_EQUALS("", errout.str());

check("int f(int x) {\n" // #11020
" const char* p = (x == 0 ? \"12345\" : \"ABC\");\n"
" int s = 0;\n"
" for (int i = 0; p[i]; i++)\n"
" s += p[i];\n"
" return s;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void array_index_same_struct_and_var_name() {
Expand Down