From 0de3e76b2d360e9ae73c557d0374e4f80d41f7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 28 Sep 2019 10:59:28 +0200 Subject: [PATCH] ExprEngine: Clarify when analysis is aborted --- lib/exprengine.cpp | 7 ++++++- test/testexprengine.cpp | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 09eaf3eef..9a7fc3bba 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -820,6 +820,9 @@ static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data) } } + if (!tok->valueType()) + throw std::runtime_error("Expression '" + tok->expressionString() + "' has unknown type!"); + auto val = getValueRangeFromValueType(data.getNewSymbolName(), tok->valueType(), *data.settings); call(data.callbacks, tok, val); return val; @@ -1011,8 +1014,10 @@ void ExprEngine::executeAllFunctions(const Tokenizer *tokenizer, const Settings for (const Scope *functionScope : symbolDatabase->functionScopes) { try { executeFunction(functionScope, tokenizer, settings, callbacks); - } catch (const std::exception &) { + } catch (const std::exception &e) { // FIXME.. there should not be exceptions + std::string functionName = functionScope->function->name(); + std::cout << "Verify: Aborted analysis of function '" << functionName << "': " << e.what(); } } } diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index 317b12884..69de253ae 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -163,7 +163,7 @@ private: } void functionCall3() { - ASSERT_EQUALS("-2147483648:2147483647", getRange("void f() { int x = -1; fgets(stdin, \"%d\", &x); x=x; }", "x=x")); + ASSERT_EQUALS("-2147483648:2147483647", getRange("int fgets(int, const char *, void *); void f() { int x = -1; fgets(stdin, \"%d\", &x); x=x; }", "x=x")); } void if1() { @@ -195,7 +195,7 @@ private: } void localArray2() { - ASSERT_EQUALS("0:255", getRange("int f() { unsigned char arr[10] = \"\"; dostuff(arr); return arr[4]; }", "arr[4]")); + ASSERT_EQUALS("0:255", getRange("void dostuff(unsigned char *); int f() { unsigned char arr[10] = \"\"; dostuff(arr); return arr[4]; }", "arr[4]")); } void localArray3() {