From e3196502784b11c70d6e3c33159403d2f7c118e1 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 25 Jul 2020 00:00:00 -0500 Subject: [PATCH] misc: eliminate a couple of miscellaneous gcc warnings This commit just addresses those warnings shown below. Reference(s): proc/sysinfo.c: In function `getrunners': proc/sysinfo.c:491:26: warning: `%s' directive writing up to 255 bytes into a region of size 26 [-Wformat-overflow=] 491 | sprintf(tbuf, "/proc/%s/stat", ent->d_name); | ^~ pgrep.c: In function `select_procs': pgrep.c:591:11: warning: suggest explicit braces to avoid ambiguous `else' [-Wdangling-else] 591 | else if (opt_older) | ^ Signed-off-by: Jim Warner --- pgrep.c | 3 ++- proc/sysinfo.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pgrep.c b/pgrep.c index 58a8842b..4b64c1a1 100644 --- a/pgrep.c +++ b/pgrep.c @@ -588,8 +588,9 @@ static struct el * select_procs (int *num) match = match_strlist (tty, opt_term); } } - else if (opt_older) + else if (opt_older) { if(now - uptime_secs + (task.start_time / Hertz) + opt_older > now) match = 0; + } else if (opt_runstates) { match = 0; if (strchr(opt_runstates, task.state)) match = 1; diff --git a/proc/sysinfo.c b/proc/sysinfo.c index 4b2090be..5daa70b2 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -488,7 +488,7 @@ static void getrunners(unsigned int *restrict running, unsigned int *restrict bl char c; if (!isdigit(ent->d_name[0])) continue; - sprintf(tbuf, "/proc/%s/stat", ent->d_name); + snprintf(tbuf, sizeof(tbuf), "/proc/%s/stat", ent->d_name); fd = open(tbuf, O_RDONLY, 0); if (fd == -1) continue;