Fix format-truncation and strncpy compiler warnings#60
Merged
folkertvanheusden merged 1 commit intoJan 2, 2026
Merged
Conversation
Increased buffer sizes in `utils.c` and `ui.c` to accommodate the full
range of integer values (preventing possible truncation).
Replaced `strncpy` with `snprintf` in `ui.c` to ensure destination
buffers are always null-terminated and free of garbage data.
Fixes the following warning:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c: In function ‘amount_to_str’:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c:371:52: warning: ‘__snprintf_chk’ output may be truncated before the last format character [-Wformat-truncation=]
371 | snprintf(out, AMOUNT_STR_LEN, "%dKB", (int)((amount + M_KB - 1) / M_KB));
| ^
In file included from /usr/include/stdio.h:974,
from /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c:7:
In function ‘snprintf’,
inlined from ‘amount_to_str’ at /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c:371:3:
/usr/include/bits/stdio2.h:68:10: note: ‘__snprintf_chk’ output between 4 and 7 bytes into a destination of size 6
68 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c: In function ‘amount_to_str’:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c:369:52: warning: ‘__snprintf_chk’ output may be truncated before the last format character [-Wformat-truncation=]
369 | snprintf(out, AMOUNT_STR_LEN, "%dMB", (int)((amount + M_MB - 1) / M_MB));
| ^
In function ‘snprintf’,
inlined from ‘amount_to_str’ at /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/utils.c:369:3:
/usr/include/bits/stdio2.h:68:10: note: ‘__snprintf_chk’ output between 4 and 7 bytes into a destination of size 6
68 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c: In function ‘edit_color’:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:155:69: warning: ‘%d’ directive output may be truncated writing between 1 and 6 bytes into a region of size 5 [-Wformat-truncation=]
155 | snprintf(val_str, sizeof(val_str), "%d", val);
| ^~
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:155:68: note: directive argument in the range [-32768, 32767]
155 | snprintf(val_str, sizeof(val_str), "%d", val);
| ^~~~
In file included from /usr/include/stdio.h:974,
from /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:5:
In function ‘snprintf’,
inlined from ‘edit_color’ at /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:155:5:
/usr/include/bits/stdio2.h:68:10: note: ‘__snprintf_chk’ output between 2 and 7 bytes into a destination of size 5
68 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c: In function ‘set_window_sizes’:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:2168:83: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 5 [-Wformat-truncation=]
2168 | snprintf(oldval, sizeof(oldval), "%d", pi[window].win_height);
| ^~
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:2168:82: note: directive argument in the range [0, 2147483647]
2168 | snprintf(oldval, sizeof(oldval), "%d", pi[window].win_height);
| ^~~~
In function ‘snprintf’,
inlined from ‘set_window_sizes’ at /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:2168:7:
/usr/include/bits/stdio2.h:68:10: note: ‘__snprintf_chk’ output between 2 and 11 bytes into a destination of size 5
68 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c: In function ‘edit_regexp’:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:1165:33: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
1165 | strncpy(dummy, (cur -> pre)[loop].cmd, min(17, strlen((cur -> pre)[loop].cmd)));
| ^
In file included from /builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:24:
/builddir/build/BUILD/multitail-7.1.5-build/multitail-7.1.5/ui.c:1165:80: note: length computed here
1165 | strncpy(dummy, (cur -> pre)[loop].cmd, min(17, strlen((cur -> pre)[loop].cmd)));
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Owner
|
Thank you for your pull requests! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Increased buffer sizes in
utils.candui.cto accommodate the full range of integer values (preventing possible truncation).Replaced
strncpywithsnprintfinui.cto ensure destination buffers are always null-terminated and free of garbage data.Fixes the following warning: