From 3bf758a04b754006463ebdbc9e971e3238a59a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 6 Dec 2020 10:13:10 +0100 Subject: [PATCH] Bug hunting; Ensure there is warning after unknown variable expression --- lib/exprengine.cpp | 2 +- test/testbughuntingchecks.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 157425388..8fbee8145 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1728,7 +1728,7 @@ static ExprEngine::ValuePtr executeAssign(const Token *tok, Data &data) } if (!rhsValue) - throw ExprEngineException(tok, "Expression '" + tok->expressionString() + "'; Failed to evaluate RHS"); + rhsValue = std::make_shared(); ExprEngine::ValuePtr assignValue; if (tok->str() == "=") diff --git a/test/testbughuntingchecks.cpp b/test/testbughuntingchecks.cpp index 8e70221d6..ebcaae6de 100644 --- a/test/testbughuntingchecks.cpp +++ b/test/testbughuntingchecks.cpp @@ -85,12 +85,24 @@ private: void arrayIndexOutOfBounds2() { check("void foo(int n) {\n" - " int p[8];" - " for (int i = 0; i < n; i++)" + " int p[8];\n" + " for (int i = 0; i < n; i++)\n" " p[i] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Array index out of bounds, cannot determine that i is less than 8\n" - "[test.cpp:2]: (error) Array index out of bounds, cannot determine that i is not negative\n", + ASSERT_EQUALS("[test.cpp:4]: (error) Array index out of bounds, cannot determine that i is less than 8\n" + "[test.cpp:4]: (error) Array index out of bounds, cannot determine that i is not negative\n", + errout.str()); + + // .. with unknown expression + check("void foo(int n) {\n" + " int p[8];\n" + " crx_data_header_t *d =\n" + " &libraw_internal_data.unpacker_data.crx_header[framei];\n" + " for (int i = 0; i < n; i++)\n" + " p[i] = 0;\n" + "}"); + ASSERT_EQUALS("[test.cpp:6]: (error) Array index out of bounds, cannot determine that i is less than 8\n" + "[test.cpp:6]: (error) Array index out of bounds, cannot determine that i is not negative\n", errout.str()); }