From 2119cd3dd55f0ae3395277672aa6758e960d9f27 Mon Sep 17 00:00:00 2001 From: Qualys Security Advisory Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] 0090-pmap: Fix output format of VmFlags. In the headers, the space was misplaced; for example, "pmap -XX $$" outputs "VmFlagsMapping" (without a space). Use justify_print() instead of printf(). There was also an extra space in the output, because vmflags[] (from the "VmFlags:" line) always ends with a space. Overwriting this last space with a null byte fixes this misalignment. Signed-off-by: Craig Small --- pmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pmap.c b/pmap.c index 7b7e60b8..57d8f04e 100644 --- a/pmap.c +++ b/pmap.c @@ -397,9 +397,11 @@ loop_end: /* === GET VMFLAGS === */ nfields = ret ? sscanf(mapbuf, "VmFlags: %"VMFL"[a-z ]", vmflags) : 0; if (nfields == 1) { + int len = strlen(vmflags); + if (len > 0 && vmflags[len-1] == ' ') vmflags[--len] = '\0'; + if (len > maxwv) maxwv = len; if (! has_vmflags) has_vmflags = 1; ret = fgets(mapbuf, sizeof mapbuf, f); - if (strlen(vmflags) > maxwv) maxwv = strlen(vmflags); } if (firstmapping == 2) { /* width measurement stage, do not print anything yet */ @@ -442,7 +444,7 @@ loop_end: justify_print(listnode->description, listnode->max_width, 1); if (has_vmflags && is_enabled("VmFlags")) - printf(" %*s", maxwv, "VmFlags "); + maxwv = justify_print("VmFlags", maxwv, 1); if (is_enabled(nls_Mapping)) justify_print(nls_Mapping, 0, 0);