Skip to content

OpenFilesScreen: use MINIMUM instead of CLAMP for unsigned column length - #2094

Open
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:clamp-to-minimum
Open

OpenFilesScreen: use MINIMUM instead of CLAMP for unsigned column length#2094
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:clamp-to-minimum

Conversation

@GermanAizek

Copy link
Copy Markdown
Contributor

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

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
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bfad784f-40f1-406c-b904-c75332c9d579

📥 Commits

Reviewing files that changed from the base of the PR and between 19fc8c1 and 5c2b19f.

📒 Files selected for processing (1)
  • OpenFilesScreen.c

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

OpenFilesScreen_getProcessData now uses MINIMUM(dlen, INT16_MAX) for the file size and file offset column widths. The changes preserve the upper bound and remove the redundant lower-bound clamp because dlen is non-negative.

Suggested reviewers: benbe

Poem

Parsed lengths march in line
Two columns gain a cleaner sign
The upper bound remains in flight
Lower clamps leave the code tonight
File size and offset align
INT16_MAX marks the line

Merge Risk: ⚪ Minimal · up to 5c2b1

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fasterit

Copy link
Copy Markdown
Member

Does the compiler not optimize this out anyways?

@fasterit fasterit added question ❔ Further information is requested code quality ♻️ Code quality enhancement labels Aug 30, 2026
@GermanAizek

Copy link
Copy Markdown
Contributor Author

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.

@BenBE

BenBE commented Sep 5, 2026

Copy link
Copy Markdown
Member

Any progress regarding your comparison?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality ♻️ Code quality enhancement question ❔ Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants