From 62367defa2de567f24d44656af335187ecefd412 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sun, 1 Oct 2017 11:59:59 -0500 Subject: [PATCH] ps: don't use '+' truncation indicator with multi-byte 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 --- ps/output.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ps/output.c b/ps/output.c index 82384eac..573666c6 100644 --- a/ps/output.c +++ b/ps/output.c @@ -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); }