Avoid 'deleteThis' in TemplateSimplifier::simplifyCalculations as it can cause 'use after free' see #6021

This commit is contained in:
Daniel Marjamäki 2017-06-07 19:46:02 +02:00
parent 18abe4a142
commit d335412858
1 changed files with 4 additions and 4 deletions

View File

@ -1083,12 +1083,12 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
tok = tok->previous(); tok = tok->previous();
if (Token::Match(tok->tokAt(-4), "[;{}] %name% = %name% [+-|] 0 ;") && if (Token::Match(tok->tokAt(-4), "[;{}] %name% = %name% [+-|] 0 ;") &&
tok->strAt(-3) == tok->previous()->str()) { tok->strAt(-3) == tok->previous()->str()) {
tok = tok->tokAt(-3); tok = tok->tokAt(-4);
tok->deleteNext(5);
} else {
tok = tok->previous();
tok->deleteNext(2); tok->deleteNext(2);
tok->deleteThis();
} }
tok->deleteNext();
tok->deleteThis();
ret = true; ret = true;
} else if (Token::Match(tok->previous(), "[=([,] 0 [+|]") || } else if (Token::Match(tok->previous(), "[=([,] 0 [+|]") ||
Token::Match(tok->previous(), "return|case 0 [+|]")) { Token::Match(tok->previous(), "return|case 0 [+|]")) {