-
-
Notifications
You must be signed in to change notification settings - Fork 482
Clang [-Wshorten-64-to-32] warnings in htop code #1673
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
Comments
The first set of changes from #1669 has been merged. The others follow soon … |
Explorer09
added a commit
to Explorer09/htop-1
that referenced
this issue
May 22, 2025
Specifically in these functions: Action_setScreenTab() TextMeterMode_draw() LEDMeterMode_draw() RowField_keyAt() drawTab() (ScreenManager.c) The strnlen() function does not calculate true display widths of the Unicode strings, but at least it works with ASCII strings. The function that can calculate display widths of Unicode strings is yet to be implemented. The goal of this commit is to prevent potential arithmetic overflows when calculating string widths and to allow a safe downcast from 'size_t' to 'int' type. This fixes some of the '-Wshorten-64-to-32' warnings produced by Clang (see issue htop-dev#1673) as a result. Signed-off-by: Kang-Che Sung <[email protected]>
Explorer09
added a commit
to Explorer09/htop-1
that referenced
this issue
May 22, 2025
Specifically in these functions: Action_setScreenTab() TextMeterMode_draw() LEDMeterMode_draw() RowField_keyAt() drawTab() (ScreenManager.c) The strnlen() function does not calculate true display widths of the Unicode strings, but at least it works with ASCII strings. The function that can calculate display widths of Unicode strings is yet to be implemented. The goal of this commit is to prevent potential arithmetic overflows when calculating string widths and to allow a safe downcast from 'size_t' to 'int' type. This fixes some of the '-Wshorten-64-to-32' warnings produced by Clang (see issue htop-dev#1673) as a result. Signed-off-by: Kang-Che Sung <[email protected]>
Explorer09
added a commit
to Explorer09/htop-1
that referenced
this issue
May 27, 2025
Specifically in these functions: Action_setScreenTab() TextMeterMode_draw() LEDMeterMode_draw() RowField_keyAt() drawTab() (ScreenManager.c) The strnlen() function does not calculate true display widths of the Unicode strings, but at least it works with ASCII strings. The function that can calculate display widths of Unicode strings is yet to be implemented. The goal of this commit is to prevent potential arithmetic overflows when calculating string widths and to allow a safe downcast from 'size_t' to 'int' type. This fixes some of the '-Wshorten-64-to-32' warnings produced by Clang (see issue htop-dev#1673) as a result. Signed-off-by: Kang-Che Sung <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This spreadsheet contains all
[-Wshorten-64-to-32]
warnings that I can find within htop codebase:https://docs.google.com/spreadsheets/d/12P6VnjGBcqXA-vDI-lsBHiAsmJoruPdLBPfZ3TKNCbg/edit?usp=sharing
I didn't test all of the platforms supported in htop, but I have tried my best.
Platforms tested: Linux, FreeBSD, OpenBSD, macOS (Darwin), PCP and Unsupported
Platforms not tested: NetBSD, DragonFly BSD and Solaris
There are
151134[-Wshorten-64-to-32]
warnings in total in the attached spreadsheet.This page marks all lines with the warnings.
I have also tried categorizing the warnings on the real problems behind or how to fix them. The pull requests #1588,
#1668(merged) and#1669(merged) are parts of the solutions to these warnings.Keywords in the Notes column:
"Cmdline"
Related to byte offsets and lengths of processes' "cmdline", "comm" and "exe" path strings. The ideal solution is to promote the type of these from
int
tosize_t
. I have proposed #1588 for this."Terminal-width"
These variables or data have confusing uses of string length (
strlen
and friends) and the display width of the string (number of terminal columns the string can occupy, a lawcswidth
). I cannot totally fix the problems in this category for now, as the reworking of certain functions to refer to widths instead can be difficult. I'm not sure if a quick workaround to silence the warning could be accepted. (The workaround I had in mind is using(int)strnlen(str, INT_MAX)
.)"strto*"
These are about conversion of
atol
,strtol
,strtoul
,strtoull
etc. results to smaller integer types. There should be bound checks (or, forfast-strto*
functions, assertions on the limits)."Hashtable-key"
Related to bit widths allowed for
Hashtable
keys."PCP-Metric"
Related to the
Metric
data type in the PCP code. I won't fix this one as I have little knowledge with the PCP code.The text was updated successfully, but these errors were encountered: