ps: Stop crash if using test fields

I'm not sure if anyone actually uses these things, but if you
selected test fields on the command line ps would crash.

$ ps/pscommand -o _left
Signal 11 (SEGV) caught by pscommand (3.3.11.877-0488).
/home/csmall/Projects/procps/procps/ps/.libs/pscommand:ps/display.c:66: please report this bug
Segmentation fault

Anyway, it doesn't now:
$ ps/pscommand -o pid,_left,_left2,_right,_unlimited 1
    PID LLLLLLLL L2L2L2L2 RRRRRRRRRRR U
      1 tty7     3270/tty4      59:59 [123456789-12345] <defunct>
This commit is contained in:
Craig Small 2020-12-22 17:50:17 +11:00
parent 048820fde3
commit bed6074531

View File

@ -1415,12 +1415,14 @@ setREL1(ID_TGID)
// like "args"
static int pr_t_unlimited(char *restrict const outbuf, const proc_t *restrict const pp){
static const char *const vals[] = {"[123456789-12345] <defunct>","ps","123456789-123456"};
if (!outbuf) return 0;
(void)pp;
snprintf(outbuf, max_rightward+1, "%s", vals[lines_to_next_header%3u]);
return strlen(outbuf);
}
static int pr_t_unlimited2(char *restrict const outbuf, const proc_t *restrict const pp){
static const char *const vals[] = {"unlimited", "[123456789-12345] <defunct>","ps","123456789-123456"};
if (!outbuf) return 0;
(void)pp;
snprintf(outbuf, max_rightward+1, "%s", vals[lines_to_next_header%4u]);
return strlen(outbuf);
@ -1429,11 +1431,13 @@ static int pr_t_unlimited2(char *restrict const outbuf, const proc_t *restrict c
// like "etime"
static int pr_t_right(char *restrict const outbuf, const proc_t *restrict const pp){
static const char *const vals[] = {"999-23:59:59","99-23:59:59","9-23:59:59","59:59"};
if (!outbuf) return 0;
(void)pp;
return snprintf(outbuf, COLWID, "%s", vals[lines_to_next_header%4u]);
}
static int pr_t_right2(char *restrict const outbuf, const proc_t *restrict const pp){
static const char *const vals[] = {"999-23:59:59","99-23:59:59","9-23:59:59"};
if (!outbuf) return 0;
(void)pp;
return snprintf(outbuf, COLWID, "%s", vals[lines_to_next_header%3u]);
}
@ -1441,11 +1445,13 @@ static int pr_t_right2(char *restrict const outbuf, const proc_t *restrict const
// like "tty"
static int pr_t_left(char *restrict const outbuf, const proc_t *restrict const pp){
static const char *const vals[] = {"tty7","pts/9999","iseries/vtty42","ttySMX0","3270/tty4"};
if (!outbuf) return 0;
(void)pp;
return snprintf(outbuf, COLWID, "%s", vals[lines_to_next_header%5u]);
}
static int pr_t_left2(char *restrict const outbuf, const proc_t *restrict const pp){
static const char *const vals[] = {"tty7","pts/9999","ttySMX0","3270/tty4"};
if (!outbuf) return 0;
(void)pp;
return snprintf(outbuf, COLWID, "%s", vals[lines_to_next_header%4u]);
}