Skip to content

Fixes for build warnings on macOS with latest toolchain - #1781

Merged
natoscott merged 3 commits into
htop-dev:mainfrom
natoscott:darwin-ci-fixes
Oct 9, 2025
Merged

natoscott merged 3 commits into
htop-dev:mainfrom
natoscott:darwin-ci-fixes

Conversation

@natoscott

Copy link
Copy Markdown
Member

No description provided.

This resolves warnings observed in macOS CI builds.
@natoscott
natoscott force-pushed the darwin-ci-fixes branch 3 times, most recently from a8cdde7 to 7e7a63f Compare October 6, 2025 03:22

@BenBE BenBE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing too critical …

Comment thread Panel.c Outdated
Comment thread darwin/DarwinMachine.c
Comment thread Vector.c
@Explorer09

Copy link
Copy Markdown
Contributor

I need to take time to review this. This is obviously a subset of issue #1673. But a few of the changes there require promoting or demoting the data types of certain structures so I didn't start working on that.

Comment thread Header.c
const int numCols = HeaderLayout_getColumns(this->headerLayout);
const int width = COLS - 2 * pad - (numCols - 1);
const size_t numCols = HeaderLayout_getColumns(this->headerLayout);
const int width = COLS - 2 * pad - ((int)numCols - 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. If numCols needs to be downcast, then numCols should be an unsigned int type. Using size_t would be overkill.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numCols was previously being downcast implicitly (HeaderLayout_getColumns returns size_t), now it is explicit. The use of an explicit cast here now is to limit the scope of changes to a small, manageable set. I expect many more things will transition to size_t, ideally also in small manageable increments, and these explicit casts will be slowly dropped out of the code over time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natoscott I previously suggested that HeaderLayout_getColumns should return int or unsigned int in order to align with the type limit of terminal columns (COLS). size_t brings no advantage here. If the number of columns in HeaderLayout is greater than COLS then some columns will never be displayed. In other words it makes no sense to allocate so many columns for the Header UI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Explorer09 you're advocating for an unrelated change to HeaderLayout_getColumns - this PR aims for a minimal set of changes to resolve the immediate CI issue, so I'm going to leave this aspect as-is.

@BenBE

BenBE commented Oct 9, 2025

Copy link
Copy Markdown
Member

Changes LGTM for now. I think we can merge this as-is and expand the patch set later.

@natoscott
natoscott merged commit 7e6e363 into htop-dev:main Oct 9, 2025
19 checks passed
@natoscott
natoscott deleted the darwin-ci-fixes branch October 9, 2025 07:27
Comment thread Panel.c
case KEY_CTRL('E'):
case '$':
this->scrollH = MAXIMUM(this->selectedLen - this->w, 0);
this->scrollH = CLAMP((int)this->selectedLen - this->w, 0, INT_MAX);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to remind that this CLAMP at INT_MAX doesn't really work. Signed integer overflow is undefined behavior, and the compiler can safely assume any (int)x > INT_MAX is false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an intermediary solution, as the upper limit by ncurses is INT_MAX (based on their API), but when transitioning to size_t later, this will become a proper bound. A proper compiler will optimize this current check out (as unnecessary), but this nonetheless documents the proper, expected limits of the values in the calculation (which is why I suggested this change in the first place).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenBE Yeah, except that Panel.scrollH should probably not migrate to size_t in the first place.
I still find this CLAMP macro call weird. Until I get a big picture about the Panel data structure, I would leave this one as is for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annoying thing with n curse s is their antiquated API, which has been left behind in the Stone Ages of computer science. So regardless of what you do, you'll end up doing some form of casts to put data to n curse s or retrieve information from the API; but inside htop we should strive to be consistent with anything referencing object counts to use size_t. And that's where things will escalate quickly; e.g. with the Vector API, which is references in many places where also drawing stuff is involved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenBE No, that wasn't what I mean. I'm aware of "curses" APIs and their limitations. What I had is another API limitation that comes from wcwidth(3) and its family. In particular, I don't think we can make the type of terminal-width-related things anything larger than signed int. Using size_t for Vector sizes is fine. My concern was on members representing terminal width or columns. Because of wcwidth limitation, we're doomed (i.e. using any type larger than int will be futile).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and that's exactly, what the intention with the CLAMP is: Use proper types to present the semantics (size_t), while ensuring the proper range (CLAMP) …

I even had a quick look earlier to see if I remember correctly about the limits of the console output stuff (somehow was wondering if it was int16_t or int32_t).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants