]> granicus.if.org Git - procps-ng/commitdiff
pmap: finally silence a warning without creating a bug
authorJim Warner <james.warner@comcast.net>
Mon, 16 May 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Mon, 16 May 2016 09:58:20 +0000 (19:58 +1000)
The patch referenced below silenced an 'uninitialized'
compiler warning but it also created a bug where zeros
appeared under the Address column with that -x option.

So this commit swats that bug and avoids any warnings.

[ while yours truly created that bug, in his defense ]
[ let's at least acknowledge the god awful loop code ]
[ which was the root of the problem & wrong solution ]

[ so the ugliness of this most recent solution is in ]
[ perfect harmony with the *really* ugly loop itself ]

Reference(s):
commit 0299bd15b0d6f0e8c3524b0383ce0bbcab66c4c5

Signed-off-by: Jim Warner <james.warner@comcast.net>
pmap.c

diff --git a/pmap.c b/pmap.c
index 19e9f1c03df43b4d399fd957c990b9e02834d6a6..626e9ee96186445ff5c4102247069bab1afa14e9 100644 (file)
--- a/pmap.c
+++ b/pmap.c
@@ -514,6 +514,9 @@ loop_end:
        /* We don't free() the list, it's used for all PIDs passed as arguments */
 }
 
+       // variable placed here to silence compiler 'uninitialized' warning
+static unsigned long start_To_Avoid_Warning;
+
 static int one_proc (struct pids_stack *p)
 {
        char buf[32];
@@ -584,7 +587,7 @@ static int one_proc (struct pids_stack *p)
                char perms[32];
                /* to clean up unprintables */
                char *tmp;
-               unsigned long end, start = 0;;
+               unsigned long end;
                unsigned long long file_offset, inode;
                unsigned dev_major, dev_minor;
                unsigned long long smap_value;
@@ -614,7 +617,7 @@ static int one_proc (struct pids_stack *p)
                                if (strncmp("Swap", smap_key, 4) == 0) {
                                        /*doesn't matter as long as last */
                                        printf("%0*lx %*lu %*llu %*llu %*s %s\n",
-                                              maxw1, start,
+                                              maxw1, start_To_Avoid_Warning,
                                               maxw2, (unsigned long)(diff >> 10),
                                               maxw3, rss,
                                               maxw4, (private_dirty + shared_dirty),
@@ -629,13 +632,14 @@ static int one_proc (struct pids_stack *p)
                                continue;
                        }
                }
-               sscanf(mapbuf, "%lx-%lx %31s %llx %x:%x %llu", &start,
+               sscanf(mapbuf, "%lx-%lx %31s %llx %x:%x %llu",
+                      &start_To_Avoid_Warning,
                       &end, perms, &file_offset, &dev_major, &dev_minor,
                       &inode);
 
                if (end - 1 < range_low)
                        continue;
-               if (range_high < start)
+               if (range_high < start_To_Avoid_Warning)
                        break;
 
                tmp = strchr(mapbuf, '\n');
@@ -648,7 +652,7 @@ static int one_proc (struct pids_stack *p)
                        tmp++;
                }
 
-               diff = end - start;
+               diff = end - start_To_Avoid_Warning;
                if (perms[3] == 's')
                        total_shared += diff;
                if (perms[3] == 'p') {
@@ -667,17 +671,17 @@ static int one_proc (struct pids_stack *p)
 
                if (x_option) {
                        cp2 =
-                           mapping_name(p, start, diff, mapbuf, map_desc_showpath, dev_major,
+                           mapping_name(p, start_To_Avoid_Warning, diff, mapbuf, map_desc_showpath, dev_major,
                                         dev_minor, inode);
                        /* printed with the keys */
                        continue;
                }
                if (d_option) {
                        const char *cp =
-                           mapping_name(p, start, diff, mapbuf, map_desc_showpath, dev_major,
+                           mapping_name(p, start_To_Avoid_Warning, diff, mapbuf, map_desc_showpath, dev_major,
                                         dev_minor, inode);
                        printf("%0*lx %*lu %*s %0*llx %*.*s%03x:%05x %s\n",
-                              maxw1, start,
+                              maxw1, start_To_Avoid_Warning,
                               maxw2, (unsigned long)(diff >> 10),
                               maxw3, perms,
                               maxw4, file_offset,
@@ -686,12 +690,12 @@ static int one_proc (struct pids_stack *p)
                }
                if (!x_option && !d_option) {
                        const char *cp =
-                           mapping_name(p, start, diff, mapbuf, map_desc_showpath, dev_major,
+                           mapping_name(p, start_To_Avoid_Warning, diff, mapbuf, map_desc_showpath, dev_major,
                                         dev_minor, inode);
                        printf((sizeof(long) == 8)
                               ? "%016lx %6luK %s %s\n"
                               : "%08lx %6luK %s %s\n",
-                              start, (unsigned long)(diff >> 10), perms, cp);
+                              start_To_Avoid_Warning, (unsigned long)(diff >> 10), perms, cp);
                }
 
        }