From e54d67799900b3e30b0397f2e1d958916bf22fac Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Thu, 29 Sep 2022 12:43:47 +0200 Subject: [PATCH] candump: main(): fix scope of fname Reported-by: https://github.com/HBLocker Link: https://github.com/linux-can/can-utils/issues/379 --- candump.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/candump.c b/candump.c index f992bb9..680166f 100644 --- a/candump.c +++ b/candump.c @@ -317,7 +317,8 @@ int main(int argc, char **argv) struct timeval tv, last_tv; int timeout_ms = -1; /* default to no timeout */ FILE *logfile = NULL; - char *logname = NULL; + char fname[83]; /* suggested by -Wformat-overflow= */ + const char *logname = NULL; signal(SIGTERM, sigterm); signal(SIGHUP, sigterm); @@ -669,7 +670,6 @@ int main(int argc, char **argv) if (!logname) { time_t currtime; struct tm now; - char fname[83]; /* suggested by -Wformat-overflow= */ if (time(&currtime) == (time_t)-1) { perror("time"); @@ -678,7 +678,7 @@ int main(int argc, char **argv) localtime_r(&currtime, &now); - sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log", + snprintf(fname, sizeof(fname), "candump-%04d-%02d-%02d_%02d%02d%02d.log", now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,