]> granicus.if.org Git - procps-ng/commitdiff
pwdx: fix compiler warning
authorSami Kerola <kerolasa@iki.fi>
Sat, 25 Feb 2012 21:24:58 +0000 (22:24 +0100)
committerCraig Small <csmall@enc.com.au>
Sat, 3 Mar 2012 07:35:35 +0000 (18:35 +1100)
pwdx.c:96:3: warning: ISO C90 forbids variable length array 'buf' [-Wvla]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
pwdx.c

diff --git a/pwdx.c b/pwdx.c
index 681397d0c683011f1acc9085678dd50aad6638a5..24c7b8d8e49c882acd0f6403a3915e98d9d83802 100644 (file)
--- a/pwdx.c
+++ b/pwdx.c
@@ -22,6 +22,7 @@
 #include "proc/version.h"
 #include "c.h"
 #include "nls.h"
+#include "xalloc.h"
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
@@ -91,9 +92,11 @@ int main(int argc, char *argv[])
 
        for (i = 0; i < argc; i++) {
                char *s;
-               ssize_t len;
+               ssize_t len, buflen;
                /* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
-               char buf[10 + strlen(argv[i]) + 1];
+               char *buf;
+               buflen = 10 + strlen(argv[i]) + 1;
+               buf = xmalloc(buflen);
 
                if (check_pid_argument(argv[i]))
                        xerrx(EXIT_FAILURE, _("invalid process id: %s"),
@@ -104,9 +107,9 @@ int main(int argc, char *argv[])
                 * the first char is possible
                 */
                if (argv[i][0] != '/')
-                       snprintf(buf, sizeof buf, "/proc/%s/cwd", argv[i]);
+                       snprintf(buf, buflen, "/proc/%s/cwd", argv[i]);
                else
-                       snprintf(buf, sizeof buf, "%s/cwd", argv[i]);
+                       snprintf(buf, buflen, "%s/cwd", argv[i]);
 
                /*
                 * buf contains /proc/NNNN/cwd symlink name
@@ -116,6 +119,7 @@ int main(int argc, char *argv[])
                        alloclen *= 2;
                        pathbuf = realloc(pathbuf, alloclen);
                }
+               free(buf);
 
                if (len < 0) {
                        s = strerror(errno == ENOENT ? ESRCH : errno);