]> granicus.if.org Git - procps-ng/commitdiff
misc: eliminate a couple of miscellaneous gcc warnings
authorJim Warner <james.warner@comcast.net>
Sat, 25 Jul 2020 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Wed, 29 Jul 2020 08:58:33 +0000 (18:58 +1000)
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 <james.warner@comcast.net>
pgrep.c
proc/sysinfo.c

diff --git a/pgrep.c b/pgrep.c
index 58a8842b7ce02c9173f44225c700fc55c175332b..4b64c1a14b63ab29beac5a31bc0c13c06968bc23 100644 (file)
--- 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;
index 4b2090be948ca54281dd1fc5f1a65b8a9d875162..5daa70b264ea0fbfd0567644cabff5fa580d7bb8 100644 (file)
@@ -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;