Repository navigation
Fix #15225 (FN arrayIndexOutOfBounds: sizeof(arr) unknown when the array dimension contains sizeof of a struct, variable or dereference) #9037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danmar
merged 4 commits into
cppcheck-opensource:main
from
JayToltTech:fix-15225-array-dim-early
Nov 25, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5870344
Fix #15225 (FN arrayIndexOutOfBounds: sizeof(arr) unknown when the ar…
JayToltTech 935cae0
Use linkAt(-1) in valueFlowArrayDimensions to fix selfcheck redundant…
JayToltTech 37c4492
Treat an array of std::array parameter as decayed in isDecayedArrayAr…
JayToltTech 3565303
Leave template-argument array dimensions to setArrayDimensionsUsingVa…
JayToltTech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
This loop also goes over dimensions that come from a template argument, where
Token::Match(dimension.tok->previous(), "[<,]")is true.setArrayDimensionsUsingValueFlow()handles those separately, becausedimension.tokthere is only the first token of the argument and there may be no AST. Heredimension.tok->getKnownValue()returns the value of that first token. Becausenumis then non-zero, the later pass skips the dimension and never corrects it.On the PR,
sizeof(a)gets the value 3, and cppcheck reportsArray 'buf[3]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]. Base gives no warning.One possible fix is to skip dimensions where
Token::Match(dimension.tok->previous(), "[<,]")and leave them tosetArrayDimensionsUsingValueFlow().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 3565303.
valueFlowArrayDimensions()now skips dimensions that come from a template argument ([<,]beforedimension.tok) and leaves them tosetArrayDimensionsUsingValueFlow(), as you suggested.Your repro no longer warns, and
sizeof(a)is 14. I added it toTestBufferOverrun::array_index_79, where it fails without the change.