OpenFilesScreen: use MINIMUM instead of CLAMP for unsigned column length - #2094
OpenFilesScreen: use MINIMUM instead of CLAMP for unsigned column length#2094GermanAizek wants to merge 1 commit into
Conversation
The CLAMP(x, low, high) macro expands to a range check that calls MAXIMUM(x, low), which results in the evaluation of the subexpression dlen > 0 dlen is of type size_t (unsigned) and dlen is known to be >= 0, the expression is inside the if (dlen > (size_t)pdata->cols[index]) block, where pdata->cols[index] >= 0 (therefore, dlen > 0 is guaranteed to be true), the lower bound (0) is redundant, and the analyzer correctly identifies the condition as constant
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough
Suggested reviewers: Poem
Merge Risk: ⚪ Minimal · up to This change removes a redundant unsigned lower-bound check while preserving the existing maximum display width, with no actionable merge-blocking risk remaining. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Does the compiler not optimize this out anyways? |
If you'd like, I can disassemble this line code with -O3 optimization flag, and we can compare the changes. |
|
Any progress regarding your comparison? |
The CLAMP(x, low, high) macro expands to a range check that calls MAXIMUM(x, low), which results in the evaluation of the subexpression dlen > 0
dlen is of type size_t (unsigned) and dlen is known to be >= 0, the expression is inside the if (dlen > (size_t)pdata->cols[index]) block, where pdata->cols[index] >= 0 (therefore, dlen > 0 is guaranteed to be true), the lower bound (0) is redundant, and the analyzer correctly identifies the condition as constant