Skip to content

Commit 948475f

Browse files
acmelgregkh
authored andcommitted
perf ui helpline: Use strlcpy() as a shorter form of strncpy() + explicit set nul
commit 4d0f16d upstream. The strncpy() function may leave the destination string buffer unterminated, better use strlcpy() that we have a __weak fallback implementation for systems without it. In this case we are actually setting the null byte at the right place, but since we pass the buffer size as the limit to strncpy() and not it minus one, gcc ends up warning us about that, see below. So, lets just switch to the shorter form provided by strlcpy(). This fixes this warning on an Alpine Linux Edge system with gcc 8.2: ui/tui/helpline.c: In function 'tui_helpline__push': ui/tui/helpline.c:27:2: error: 'strncpy' specified bound 512 equals destination size [-Werror=stringop-truncation] strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0'; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Cc: Adrian Hunter <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Fixes: e6e9046 ("perf ui: Introduce struct ui_helpline") Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e20ec78 commit 948475f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/ui/tui/helpline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void tui_helpline__push(const char *msg)
2323
SLsmg_set_color(0);
2424
SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
2525
SLsmg_refresh();
26-
strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
26+
strlcpy(ui_helpline__current, msg, sz);
2727
}
2828

2929
static int tui_helpline__show(const char *format, va_list ap)

0 commit comments

Comments
 (0)