diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 438b5a115..eaf1d05b1 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1593,6 +1593,8 @@ void CheckBufferOverrun::checkStringArgument() for (const Token *argtok = tok->tokAt(2); argtok; argtok = argtok->nextArgument(), argnr++) { if (!Token::Match(argtok, "%name%|%str% ,|)")) continue; + if (argtok->variable() && !argtok->variable()->isPointer()) + continue; const Token *strtoken = argtok->getValueTokenMinStrSize(); if (!strtoken) continue; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index a8f044e0a..c775b0bc9 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3094,6 +3094,12 @@ private: " mymemset(temp, \"abc\", 4);\n" "}", settings); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" // #6816 - fp when array has known string value + " const char c[10] = \"c\";\n" + " mymemset(c, 0, 10);\n" + "}", settings); + ASSERT_EQUALS("", errout.str()); } void minsize_sizeof() {