File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,11 +160,13 @@ namespace ValueFlow
160160 value.setKnown ();
161161 setTokenValue (tok, std::move (value), settings);
162162 } else if (Token::simpleMatch (tok, " sizeof (" )) {
163- if (tok->next ()->astOperand2 () && !tok->next ()->astOperand2 ()->isLiteral () && tok->next ()->astOperand2 ()->valueType () &&
164- (tok->next ()->astOperand2 ()->valueType ()->pointer == 0 || // <- TODO this is a bailout, abort when there are array->pointer conversions
165- (tok->next ()->astOperand2 ()->variable () && !tok->next ()->astOperand2 ()->variable ()->isArray ())) &&
166- !tok->next ()->astOperand2 ()->valueType ()->isEnum ()) { // <- TODO this is a bailout, handle enum with non-int types
167- const size_t sz = tok->next ()->astOperand2 ()->valueType ()->getSizeOf (settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer);
163+ const Token* const obj = tok->next ()->astOperand2 ();
164+ if (obj && !obj->isLiteral () && obj->valueType () &&
165+ (obj->valueType ()->pointer == 0 || // <- TODO this is a bailout, abort when there are array->pointer conversions
166+ (obj->variable () && !obj->variable ()->isArray ())) &&
167+ !obj->valueType ()->isEnum ()) { // <- TODO this is a bailout, handle enum with non-int types
168+ const auto ptrPointee = obj->valueType ()->pointer > 0 ? ValueType::SizeOf::Pointer : ValueType::SizeOf::Pointee;
169+ const size_t sz = obj->valueType ()->getSizeOf (settings, ValueType::Accuracy::ExactOrZero, ptrPointee);
168170 if (sz) {
169171 Value value (sz);
170172 value.setKnown ();
You can’t perform that action at this time.
0 commit comments