CheckBufferOverrun::checkStringArgument: sizeof string is strlen+1

This commit is contained in:
Daniel Marjamäki 2014-07-08 16:04:09 +02:00
parent 9a4bd73a18
commit 254b6438b9
2 changed files with 6 additions and 1 deletions

View File

@ -1540,7 +1540,7 @@ void CheckBufferOverrun::checkStringArgument()
const std::list<Library::ArgumentChecks::MinSize> *minsizes = _settings->library.argminsizes(tok->str(), argnr);
if (!minsizes)
continue;
if (checkMinSizes(*minsizes, tok, Token::getStrLength(argtok), nullptr))
if (checkMinSizes(*minsizes, tok, Token::getStrLength(argtok)+1U, nullptr))
bufferOverrunError(argtok);
}
}

View File

@ -2246,6 +2246,11 @@ private:
" memcpy(temp, \"hello world\", 20);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Buffer is accessed out of bounds.\n", errout.str());
checkstd("void f() {\n"
" memcpy(temp, \"abc\", 4);\n"
"}");
ASSERT_EQUALS("", errout.str());
}