CheckBufferOverrun: Remove old checking of strings and use new ValueFlow-based checking instead (#6973)
This commit is contained in:
parent
8fb6f33aca
commit
9c3f25603e
|
@ -1179,13 +1179,6 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
||||||
type = tok->strAt(4);
|
type = tok->strAt(4);
|
||||||
var = tok->next()->variable();
|
var = tok->next()->variable();
|
||||||
nextTok = 8;
|
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% ) ;")) {
|
} else if (Token::Match(tok, "[*;{}] %var% = malloc|alloca ( %num% ) ;")) {
|
||||||
size = MathLib::toLongNumber(tok->strAt(5));
|
size = MathLib::toLongNumber(tok->strAt(5));
|
||||||
type = "char"; // minimum type, typesize=1
|
type = "char"; // minimum type, typesize=1
|
||||||
|
|
|
@ -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());
|
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() {
|
void array_index_same_struct_and_var_name() {
|
||||||
|
|
Loading…
Reference in New Issue