diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index f37fcd5a3..535609f65 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -361,6 +361,10 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int for (std::size_t i = 0; i < arrayInfo.num().size(); ++i) arraySize *= arrayInfo.num(i); + // dimension is 0 or unknown => bailout + if (arraySize == 0) + return; + const Token *charSizeToken = nullptr; if (checkMinSizes(*minsizes, &ftok, (std::size_t)arraySize, &charSizeToken, _settings)) bufferOverrunError(callstack, arrayInfo.varname()); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 165fbe517..7f984cb62 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3261,6 +3261,15 @@ private: " mysprintf(x.a, \"aa\");\n" "}", settings); ASSERT_EQUALS("", errout.str()); + + check("struct Foo {\n" // #6668 - unknown size + " char a[LEN];\n" + " void f();\n" + "};" + "void Foo::f() {\n" + " mysprintf(a, \"abcd\");\n" + "}", settings); + ASSERT_EQUALS("", errout.str()); } void minsize_mul() {