Constructor parameter type need not be a number

This commit is contained in:
Dmitry-Me 2015-03-25 14:56:45 +03:00
parent 9846ff10b2
commit d735918a8a
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"