Merge pull request #576 from Dmitry-Me/anyParameterType

Constructor parameter type need not be a number
This commit is contained in:
PKEuS 2015-04-01 11:29:44 +02:00
commit 04a3196a32
2 changed files with 7 additions and 1 deletions

View File

@ -1064,7 +1064,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
if (size < 0) {
negativeMemoryAllocationSizeError(tok->next()->next());
}
} else if (Token::Match(tok, "[*;{}] %var% = new %type% ( %num% )")) {
} else if (Token::Match(tok, "[*;{}] %var% = new %type% ( %num%|%name% )")) {
size = 1;
type = tok->strAt(4);
var = tok->next()->variable();

View File

@ -3242,6 +3242,12 @@ private:
"}", settings);
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
check("void f(char value) {\n"
" char *a = new char(value);\n"
" mysprintf(a, \"a\");\n"
"}", settings);
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
// This is out of bounds if 'sizeof(ABC)' is 1 (No padding)
check("struct Foo { char a[1]; };\n"
"void f() {\n"