Buffer overrun errors behind function call should be possible errors.
This commit is contained in:
parent
3dc45903bc
commit
be90d34962
|
@ -76,7 +76,19 @@ void CheckBufferOverrun::arrayIndexOutOfBounds(int size)
|
|||
|
||||
void CheckBufferOverrun::bufferOverrun(const Token *tok)
|
||||
{
|
||||
reportError(tok, Severity::error, "bufferOverrun", "Buffer overrun");
|
||||
Severity::e severity;
|
||||
if (_callStack.size() > 0)
|
||||
{
|
||||
severity = Severity::possibleError;
|
||||
if (_settings->_showAll == false)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
severity = Severity::error;
|
||||
}
|
||||
|
||||
reportError(tok, severity, "bufferOverrun", "Buffer overrun");
|
||||
}
|
||||
|
||||
void CheckBufferOverrun::dangerousStdCin(const Token *tok)
|
||||
|
|
|
@ -35,7 +35,7 @@ private:
|
|||
|
||||
|
||||
|
||||
void check(const char code[])
|
||||
void check(const char code[], bool showAll = true)
|
||||
{
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer;
|
||||
|
@ -54,7 +54,7 @@ private:
|
|||
|
||||
// Check for buffer overruns..
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
settings._showAll = showAll;
|
||||
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
}
|
||||
|
@ -681,6 +681,30 @@ private:
|
|||
" p[1] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// There is no error here
|
||||
check("void f1(char *s,int size)\n"
|
||||
"{\n"
|
||||
" if( size > 10 ) strcpy(s,\"abc\");\n"
|
||||
"}\n"
|
||||
"void f2()\n"
|
||||
"{\n"
|
||||
" char s[3];\n"
|
||||
" f1(s,3);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (possible error) Buffer overrun\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f1(char *s,int size)\n"
|
||||
"{\n"
|
||||
" if( size > 10 ) strcpy(s,\"abc\");\n"
|
||||
"}\n"
|
||||
"void f2()\n"
|
||||
"{\n"
|
||||
" char s[3];\n"
|
||||
" f1(s,3);\n"
|
||||
"}\n", false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_5()
|
||||
|
|
Loading…
Reference in New Issue