]> granicus.if.org Git - procps-ng/commitdiff
ps: don't use '+' truncation indicator with multi-byte
authorJim Warner <james.warner@comcast.net>
Sun, 1 Oct 2017 16:59:59 +0000 (11:59 -0500)
committerCraig Small <csmall@enc.com.au>
Mon, 2 Oct 2017 11:20:58 +0000 (22:20 +1100)
The ps program generally supports multi-byte sequences
in strings representing user and group names. However,
should a multi-byte sequence span the maximum width of
a column, the '+' inserted by ps to signify truncation
will corrupt that sequence, misaligning the text line.

Unfortunately, there's insufficient info returned from
the escape_str function (who calls escape_str_utf8) to
provide a robust response. So, this commit will revert
to the old standby of displaying a number when the '+'
character would've corrupted that multi-byte sequence.

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

index 82384eac7504d0edc8759575d8cf2e2a95d4b461..573666c6664f3bc3e16689a41d7739b3d0fb4a76 100644 (file)
@@ -1136,10 +1136,13 @@ static int do_pr_name(char *restrict const outbuf, const char *restrict const na
     if(len <= (int)max_rightward)
       return len;  /* returns number of cells */
 
-    len = max_rightward-1;
-    outbuf[len++] = '+';
-    outbuf[len] = 0;
-    return len;
+    // only use '+' when not on a multi-byte char, else show uid
+    if ((unsigned)outbuf[max_rightward-1] < 127) {
+      len = max_rightward-1;
+      outbuf[len++] = '+';
+      outbuf[len] = 0;
+      return len;
+    }
   }
   return snprintf(outbuf, COLWID, "%u", u);
 }