CheckBufferOverrun: Minor fixes for strings

This commit is contained in:
Daniel Marjamäki 2015-11-07 15:05:56 +01:00
parent 9a879fc828
commit d0ab3aea70
1 changed files with 4 additions and 4 deletions

View File

@ -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());
}
}