CheckBufferOverrun: Minor fixes for strings
This commit is contained in:
parent
9a879fc828
commit
d0ab3aea70
|
@ -1073,10 +1073,10 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
{
|
||||
// check string literals
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%str% [ %num% ]")) {
|
||||
const std::size_t strLen = tok->str().size() - 2; // Don't count enclosing quotes
|
||||
const std::size_t index = (std::size_t)std::atoi(tok->strAt(2).c_str());
|
||||
if (index > strLen)
|
||||
if (Token::Match(tok, "%str% [")) {
|
||||
const std::size_t strLen = Token::getStrLength(tok);
|
||||
const ValueFlow::Value *value = tok->next()->astOperand2()->getMaxValue(false);
|
||||
if (value && value->intvalue > strLen)
|
||||
bufferOverrunError(tok, tok->str());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue