]> granicus.if.org Git - procps-ng/commitdiff
library: Explicit about task ID string length
authorCraig Small <csmall@enc.com.au>
Wed, 20 Dec 2017 10:37:01 +0000 (21:37 +1100)
committerCraig Small <csmall@enc.com.au>
Wed, 20 Dec 2017 10:37:01 +0000 (21:37 +1100)
This removes the following error by stating the task ID can only be 10
characters wide, as it is an integer.

proc/readproc.c: In function ‘simple_nexttid’:
proc/readproc.c:1185:46: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 41 and 51 [-Wformat-truncation=]
   snprintf(path, PROCPATHLEN, "/proc/%d/task/%s", p->tgid, ent->d_name);
                                              ^~
proc/readproc.c:1185:3: note: ‘snprintf’ output between 14 and 279 bytes into a destination of size 64
   snprintf(path, PROCPATHLEN, "/proc/%d/task/%s", p->tgid, ent->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

proc/readproc.c

index 68619229c006c4554241e4b771063d2676e66469..1fe7ce048a15229cb0254c968ca1f160f07dae69 100644 (file)
@@ -1182,7 +1182,7 @@ static int simple_nexttid(PROCTAB *restrict const PT, const proc_t *restrict con
   t->tid = strtoul(ent->d_name, NULL, 10);
   t->tgid = p->tgid;
 //t->ppid = p->ppid;  // cover for kernel behavior? we want both actually...?
-  snprintf(path, PROCPATHLEN, "/proc/%d/task/%s", p->tgid, ent->d_name);
+  snprintf(path, PROCPATHLEN, "/proc/%d/task/%.10s", p->tgid, ent->d_name);
   return 1;
 }