mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
4d0f16d059
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 <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Fixes: e6e9046879
("perf ui: Introduce struct ui_helpline")
Link: https://lkml.kernel.org/n/tip-d1wz0hjjsh19xbalw69qpytj@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <pthread.h>
|
|
|
|
#include "../../util/debug.h"
|
|
#include "../helpline.h"
|
|
#include "../ui.h"
|
|
#include "../libslang.h"
|
|
|
|
char ui_helpline__last_msg[1024];
|
|
bool tui_helpline__set;
|
|
|
|
static void tui_helpline__pop(void)
|
|
{
|
|
}
|
|
|
|
static void tui_helpline__push(const char *msg)
|
|
{
|
|
const size_t sz = sizeof(ui_helpline__current);
|
|
|
|
SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
|
|
SLsmg_set_color(0);
|
|
SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
|
|
SLsmg_refresh();
|
|
strlcpy(ui_helpline__current, msg, sz);
|
|
}
|
|
|
|
static int tui_helpline__show(const char *format, va_list ap)
|
|
{
|
|
int ret;
|
|
static int backlog;
|
|
|
|
pthread_mutex_lock(&ui__lock);
|
|
ret = vscnprintf(ui_helpline__last_msg + backlog,
|
|
sizeof(ui_helpline__last_msg) - backlog, format, ap);
|
|
backlog += ret;
|
|
|
|
tui_helpline__set = true;
|
|
|
|
if (ui_helpline__last_msg[backlog - 1] == '\n') {
|
|
ui_helpline__puts(ui_helpline__last_msg);
|
|
SLsmg_refresh();
|
|
backlog = 0;
|
|
}
|
|
pthread_mutex_unlock(&ui__lock);
|
|
|
|
return ret;
|
|
}
|
|
|
|
struct ui_helpline tui_helpline_fns = {
|
|
.pop = tui_helpline__pop,
|
|
.push = tui_helpline__push,
|
|
.show = tui_helpline__show,
|
|
};
|
|
|
|
void ui_helpline__init(void)
|
|
{
|
|
helpline_fns = &tui_helpline_fns;
|
|
ui_helpline__puts(" ");
|
|
}
|