CheckBufferOverrun: Remove old checking of strings and use new ValueFlow-based checking instead (#6973)

This commit is contained in:
Daniel Marjamäki 2015-11-30 16:34:59 +01:00
parent 8fb6f33aca
commit 9c3f25603e
2 changed files with 5 additions and 7 deletions

View File

@ -1179,13 +1179,6 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
type = tok->strAt(4);
var = tok->next()->variable();
nextTok = 8;
} else if (Token::Match(tok, "[;{}] %var% = %str% ;") &&
tok->next()->variable() &&
tok->next()->variable()->isPointer()) {
size = 1 + int(tok->tokAt(3)->strValue().size());
type = "char";
var = tok->next()->variable();
nextTok = 4;
} else if (Token::Match(tok, "[*;{}] %var% = malloc|alloca ( %num% ) ;")) {
size = MathLib::toLongNumber(tok->strAt(5));
type = "char"; // minimum type, typesize=1

View File

@ -1997,6 +1997,11 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout.str());
check("void f() {\n" // #6973
" const char *name = \"\";\n"
" if ( name[0] == 'U' ? name[1] : 0) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void array_index_same_struct_and_var_name() {