Repository navigation
UCS/BITMAP: Add static check for bitmap loop index size - #12080
Merged
brminich merged 2 commits intoOct 19, 2026
Merged
Conversation
Signed-off-by: Guy Ealey Morag <gealeymorag@nvidia.com>
|
🤖 Starting review — findings will be posted here when done. |
tomerg-nvidia
previously approved these changes
Oct 13, 2026
Comment on lines
+377
to
+379
| #define UCS_STATIC_BITMAP_CHECK_INDEX_TYPE(_bit_index, _bitmap) \ | ||
| ((void)sizeof( \ | ||
| char[UCS_STATIC_BITMAP_INDEX_FITS(_bit_index, _bitmap) ? 1 : -1])) |
Contributor
There was a problem hiding this comment.
Suggested change
| #define UCS_STATIC_BITMAP_CHECK_INDEX_TYPE(_bit_index, _bitmap) \ | |
| ((void)sizeof( \ | |
| char[UCS_STATIC_BITMAP_INDEX_FITS(_bit_index, _bitmap) ? 1 : -1])) | |
| #define UCS_STATIC_BITMAP_CHECK_INDEX_TYPE(_bit_index, _bitmap) \ | |
| (sizeof(char[UCS_STATIC_BITMAP_INDEX_FITS(_bit_index, _bitmap) ? 1 : -1]) \ | |
| != 0) |
then
#define _UCS_BITMAP_BITS_FOR_EACH_BIT(_bit_index, _bits, _num_words, _cond) \
for (_bit_index = ucs_bitmap_bits_ffs(_bits, _num_words, 0); \
(_cond) && (_bit_index < (_num_words) * UCS_BITMAP_BITS_IN_WORD); \
_bit_index = ucs_bitmap_bits_ffs(_bits, _num_words, _bit_index + 1))
#define UCS_BITMAP_BITS_FOR_EACH_BIT(_bit_index, _bits, _num_words) \
_UCS_BITMAP_BITS_FOR_EACH_BIT(_bit_index, _bits, _num_words, 1)
#define UCS_STATIC_BITMAP_FOR_EACH_BIT(_bit_index, _bitmap_ptr) \
_UCS_BITMAP_BITS_FOR_EACH_BIT( \
_bit_index, (_bitmap_ptr)->bits, \
UCS_STATIC_BITMAP_NUM_WORDS(*(_bitmap_ptr)), \
UCS_STATIC_BITMAP_CHECK_INDEX_TYPE(_bit_index, *(_bitmap_ptr)))
Signed-off-by: Guy Ealey Morag <gealeymorag@nvidia.com>
|
🤖 Starting review — findings will be posted here when done. |
| (_src_num_words)); | ||
|
|
||
|
|
||
| /* Iterate over set bits while _cond holds */ |
There was a problem hiding this comment.
The new _cond parameter is described as a loop condition, but its only purpose (and only use) is a compile-time assertion; the name invites a runtime predicate into a shared hot iteration macro. Maybe rename _cond to _check and note it must be a compile-time constant? The current name reads like a runtime loop condition, which would silently stop the iteration early.
evgeny-leksikov
approved these changes
Oct 15, 2026
brminich
approved these changes
Oct 19, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
Make
UCS_STATIC_BITMAP_FOR_EACH_BITfail the build when the loop index type can't hold the bitmap size, and add a gtest for the size check.Why?
If the index type is too narrow for a given static bitmap size, that value wraps to 0 and we get an infinite loop.
This came up in #12054: the bitmap there is of size 256, which a
uint8_tindex can't hold.