Fixed #9113 (false positive: (error) Buffer is accessed out of bounds)

This commit is contained in:
Daniel Marjamäki 2019-11-10 16:42:48 +01:00
parent fb8b9b12cb
commit fcc5fad3ed
2 changed files with 7 additions and 0 deletions

View File

@ -588,6 +588,8 @@ void CheckBufferOverrun::bufferOverflow()
argtok = argtok->astOperand2();
if (!argtok || !argtok->variable())
continue;
if (argtok->valueType() && argtok->valueType()->pointer == 0)
continue;
// TODO: strcpy(buf+10, "hello");
const ValueFlow::Value bufferSize = getBufferSize(argtok);
if (bufferSize.intvalue <= 1)

View File

@ -3388,6 +3388,11 @@ private:
"}", settings);
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout.str());
check("void f(unsigned int addr) {\n"
" memset((void *)addr, 0, 1000);\n"
"}", settings0);
ASSERT_EQUALS("", errout.str());
check("struct AB { char a[10]; };\n"
"void foo(AB *ab) {\n"
" mystrncpy(x, ab->a, 100);\n"