You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 370d71b
Browse filesBrowse the repository at this point in the historyBrowse files
Fix #15225 (FN arrayIndexOutOfBounds: sizeof(arr) unknown when the array dimension contains sizeof of a struct, variable or dereference)
A dimension such as 10 + sizeof(struct S) was only marked known by
SymbolDatabase::setArrayDimensionsUsingValueFlow(), which runs after all
ValueFlow passes. Every reader inside ValueFlow saw it as unknown, so
sizeof(arr), sizeof(arr) / sizeof(arr[0]) and sizeof of a struct that
contains such an array got no value.
valueFlowNumber() now sets the dimension when the token walk reaches the
end of the array declaration, where constant folding has already given the
dimension token a known value. Declarations precede uses, so the existing
sizeof code then works unchanged, including for chained declarations such
as char b[sizeof(a)]. The pass after ValueFlow stays for dimensions that
only become known later.
With more dimensions known, sizeof of an array function parameter would
get the size of the array more often. It is a pointer, so sizeof now gives
the pointer size and sizeof(p) / sizeof(p[0]) is no longer evaluated as the
element count. The condition moves to Variable::isDecayedArrayArgument(),
shared with CheckSizeof.
0 commit comments