Fixed #7718 (False positive: out of bounds of already resized std::string)
This commit is contained in:
parent
aa58f41e6d
commit
20121b34d8
|
@ -1561,6 +1561,9 @@ void CheckBufferOverrun::bufferOverrun()
|
||||||
// char arr[10] = "123";
|
// char arr[10] = "123";
|
||||||
// arr[7] = 'x'; // warning: arr[7] is inside the array bounds, but past the string's end
|
// arr[7] = 'x'; // warning: arr[7] is inside the array bounds, but past the string's end
|
||||||
|
|
||||||
|
if (tok->valueType() && tok->valueType()->type == ValueType::Type::CONTAINER)
|
||||||
|
continue;
|
||||||
|
|
||||||
const ArrayInfo arrayInfo(tok->varId(), varname, 1U, Token::getStrSize(strtoken));
|
const ArrayInfo arrayInfo(tok->varId(), varname, 1U, Token::getStrSize(strtoken));
|
||||||
valueFlowCheckArrayIndex(tok->next(), arrayInfo);
|
valueFlowCheckArrayIndex(tok->next(), arrayInfo);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -74,6 +74,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() override {
|
void run() override {
|
||||||
|
LOAD_LIB_2(settings0.library, "std.cfg");
|
||||||
|
|
||||||
settings0.addEnabled("warning");
|
settings0.addEnabled("warning");
|
||||||
settings0.addEnabled("style");
|
settings0.addEnabled("style");
|
||||||
settings0.addEnabled("portability");
|
settings0.addEnabled("portability");
|
||||||
|
@ -3124,6 +3126,14 @@ private:
|
||||||
" s[10] = 0;\n"
|
" s[10] = 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo()\n" // #7718
|
||||||
|
"{\n"
|
||||||
|
" std::string s = \"123\";\n"
|
||||||
|
" s.resize(100);\n"
|
||||||
|
" s[10] = 0;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// data is allocated with alloca
|
// data is allocated with alloca
|
||||||
|
|
Loading…
Reference in New Issue