From aa05bf0f1659bffc23a458d461b0afc1e181e59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 24 Mar 2014 06:48:06 +0100 Subject: [PATCH] ValueFlow: Improved abstract interpretation --- lib/valueflow.cpp | 17 ++++++++++------- test/testbufferoverrun.cpp | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) 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() {