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 20:09:06 +02:00
parent d335412858
commit 2740736136
1 changed files with 4 additions and 4 deletions

View File

@ -1146,7 +1146,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
}
// Remove parentheses around number..
if (Token::Match(tok->tokAt(-2), "%op%|< ( %num% )") && !tok->tokAt(-2)->isName() && tok->strAt(-2) != ">") {
if (Token::Match(tok->tokAt(-2), "%op%|< ( %num% )") && tok->strAt(-2) != ">") {
tok = tok->previous();
tok->deleteThis();
tok->deleteNext();
@ -1155,10 +1155,10 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
if (Token::simpleMatch(tok->previous(), "( 0 |") ||
Token::simpleMatch(tok->previous(), "| 0 )")) {
if (tok->previous()->isConstOp())
tok = tok->previous();
if (tok->str() == "|")
tok = tok->previous();
tok->deleteNext();
tok->deleteThis();
tok->deleteNext(2);
ret = true;
}