Skip to content

Commit ab3847d

Browse files
Update vf_common.cpp
1 parent b82e866 commit ab3847d

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/vf_common.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)