2222#include " symboldatabase.h"
2323#include < algorithm>
2424#include < cctype>
25- #include < stack>
2625// ---------------------------------------------------------------------------
2726
2827// Register this check class (by creating a static instance of it)
@@ -219,45 +218,6 @@ void CheckSizeof::sizeofsizeofError(const Token *tok)
219218}
220219
221220// -----------------------------------------------------------------------------
222- // -----------------------------------------------------------------------------
223- static bool isCalculation (const Token *op)
224- {
225- if (!op)
226- return false ;
227-
228- if (!Token::Match (op, " %cop%|++|--" ))
229- return false ;
230-
231- if (Token::Match (op, " *|&" )) {
232- // dereference or address-of?
233- if (!op->astOperand2 ())
234- return false ;
235-
236- if (op->astOperand2 ()->str () == " [" )
237- return false ;
238-
239- // type specification?
240- std::stack<const Token *> operands;
241- operands.push (op);
242- while (!operands.empty ()) {
243- const Token *item = operands.top ();
244- operands.pop ();
245- if (item->isNumber () || item->varId () > 0 )
246- return true ;
247- if (item->astOperand1 ())
248- operands.push (item->astOperand1 ());
249- if (item->astOperand2 ())
250- operands.push (item->astOperand2 ());
251- else if (Token::Match (item, " *|&" ))
252- return false ;
253- }
254-
255- // type specification => return false
256- return false ;
257- }
258-
259- return true ;
260- }
261221
262222void CheckSizeof::sizeofCalculation ()
263223{
@@ -267,7 +227,7 @@ void CheckSizeof::sizeofCalculation()
267227 for (const Token *tok = _tokenizer->tokens (); tok; tok = tok->next ()) {
268228 if (Token::simpleMatch (tok, " sizeof (" )) {
269229 const Token *argument = tok->next ()->astOperand2 ();
270- if (isCalculation (argument ) && (!argument->isExpandedMacro () || _settings->inconclusive ))
230+ if (argument && argument-> isCalculation () && (!argument->isExpandedMacro () || _settings->inconclusive ))
271231 sizeofCalculationError (argument, argument->isExpandedMacro ());
272232 }
273233 }
0 commit comments