]> granicus.if.org Git - psmisc/commitdiff
killall: use correct size for comm
authorCraig Small <csmall@enc.com.au>
Mon, 27 Aug 2018 11:30:33 +0000 (21:30 +1000)
committerCraig Small <csmall@enc.com.au>
Mon, 27 Aug 2018 11:30:33 +0000 (21:30 +1000)
sizeof only works on statically created pointers, not pointers that are
passed as parameters to the function.

The referenced commit unfortunately didn't follow this and we got
truncated names. Thanks to Hector Martin for pointing the problem out.

References:
 commit 1e2f38a202798a78554ae5f5d12f697f3607f89f
 psmisc/psmisc#14

src/killall.c

index bbbc18762693a90641d1450e0f2d1f5b8ef949c3..7f982a1a2002f438483618bec76d895203fbeb3b 100644 (file)
@@ -350,8 +350,8 @@ load_process_name_and_age(char *comm, double *process_age_sec,
     lencomm = endcomm - startcomm;
     if (lencomm < 0)
         lencomm = 0;
-    if (lencomm > sizeof comm -1)
-        lencomm = sizeof comm -1;
+    if (lencomm > COMM_LEN -1)
+        lencomm = COMM_LEN -1;
     strncpy(comm, startcomm, lencomm);
     comm[lencomm] = '\0';