diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ca6b1a2d5..f9315ac15 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -688,16 +688,19 @@ static void execute(const Token *expr, } else if (expr->str() == "&&") { - execute(expr->astOperand1(), programMemory, result, error); - if (*error || *result == 0) + bool error1 = false; + execute(expr->astOperand1(), programMemory, result, &error1); + if (!error1 && *result == 0) *result = 0; else { - execute(expr->astOperand2(), programMemory, result, error); - // If there is an error, assume the result is not important - if (*error) { - *error = false; + bool error2 = false; + execute(expr->astOperand2(), programMemory, result, &error2); + if (error1 && error2) + *error = true; + if (error2) *result = 1; - } + else + *result = !!*result; } } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index b0635a136..cc55729a8 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1846,7 +1846,8 @@ private: " data[x] = 0;\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: data\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: data\n" + "[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str()); } void array_index_for_continue() {