Fix bug in $pid_cmdline
authorNikolas Garofil <garo@dunaldi.garofil.be>
Wed, 18 Nov 2009 17:02:10 +0000 (18:02 +0100)
committerNikolas Garofil <garo@dunaldi.garofil.be>
Wed, 18 Nov 2009 17:02:10 +0000 (18:02 +0100)
src/proc.c

index 50ee571..ae453b2 100644 (file)
@@ -115,18 +115,22 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
        char* buf;
        int i, bytes_read;
 
-       asprintf(&buf, PROCDIR "/%s/cmdline", obj->data.s);
-       strcpy(obj->data.s, buf);
-       free(buf);
-       buf = readfile(obj->data.s, &bytes_read, 1);
-       if(buf != NULL) {
-               for(i = 0; i < bytes_read-1; i++) {
-                       if(buf[i] == 0) {
-                               buf[i] = ' ';
+       if(*(obj->data.s) != 0) {
+               asprintf(&buf, PROCDIR "/%s/cmdline", obj->data.s);
+               strcpy(obj->data.s, buf);
+               free(buf);
+               buf = readfile(obj->data.s, &bytes_read, 1);
+               if(buf != NULL) {
+                       for(i = 0; i < bytes_read-1; i++) {
+                               if(buf[i] == 0) {
+                                       buf[i] = ' ';
+                               }
                        }
+                       snprintf(p, p_max_size, "%s", buf);
+                       free(buf);
                }
-               snprintf(p, p_max_size, "%s", buf);
-               free(buf);
+       } else {
+               NORM_ERR("$pid_cmdline didn't receive a argument");
        }
 }