-
-
Notifications
You must be signed in to change notification settings - Fork 531
Introduce strnlen() and use it for some string width calculations #1707
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
Conversation
0348583 to
b73e050
Compare
43bfd83 to
d70cffe
Compare
|
When clicking the screen tabs there's a small off-by-one present:
A similar issue exists when trying to select a column header:
|
Can't reproduce in my terminal emulator. They work perfectly on my side. Both on macOS Terminal and xfce4-terminal (on Devuan GNU/Linux). |
No code changes.
No code changes.
No changes in compiled code.
This avoids a '-Wshorten-64-to-32' warning produced by Clang. Signed-off-by: Kang-Che Sung <[email protected]>
Make the code more robust with very small width of the terminal screen. Also add assertions on x positions in the drawTab() subroutine. Signed-off-by: Kang-Che Sung <[email protected]>
Add configure check for strnlen() function and provide our own implementation for systems that doesn't support it. Co-Authored-By: Benny Baumann <[email protected]> Signed-off-by: Kang-Che Sung <[email protected]>
Specifically in these functions: Action_setScreenTab(), TextMeterMode_draw(), LEDMeterMode_draw() RowField_keyAt() and drawTab() 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]>
|
Merging for now, as this happens for me also with the previous version without this PR applied. |
The
strnlenfunction 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 not implemented in htop yet (I have #1642, but the implementation of that is incomplete).The goal of this commit is to prevent potential arithmetic overflows when calculating string widths and to allow a safe downcast from
size_ttointtype. This fixes some of the-Wshorten-64-to-32warnings produced by Clang (see #1673) as a result.