diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 1c2fd49c4..43239c20e 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -458,11 +458,6 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, const ArrayInfo &arrayInfo) { - // unknown element size : don't report errors - if (arrayInfo.element_size == 0) - return; - - std::map total_size; total_size["fgets"] = 2; // The second argument for fgets can't exceed the total size of the array total_size["memcmp"] = 3; @@ -494,6 +489,9 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c std::map::const_iterator it = total_size.find(tok.str()); if (it != total_size.end()) { + if (arrayInfo.element_size == 0) + return; + unsigned int arg = it->second; for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next()) { @@ -716,7 +714,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector(total_size)); + ArrayInfo arrayInfo(0U, varnames, total_size / size, size); if (Token::Match(tok, ("%var% ( " + varnames + " ,").c_str())) checkFunctionCall(*tok, 1, arrayInfo); if (Token::Match(tok, ("%var% ( %var% , " + varnames + " ,").c_str())) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 6562ae672..b5c9a3868 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1035,8 +1035,7 @@ private: " struct s1 obj;\n" " x(obj.delay, 123);\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6] (error) array index 4 is out of bounds", errout.str()); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj . delay[3]' index 4 out of bounds\n", errout.str()); } void array_index_multidim()