From 1005b43609bd5bd55eca1278cf762eb59702a1a1 Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Sat, 6 Feb 1999 16:58:50 +0000 Subject: Don't dump core when p_stat is not in the expected range. This is only likely to happen when you have a kernel<>userland mismatch, but it's really annoying when top dumps core and leaves the terminal in a mangled state; it's much nicer to print nicely formatted gibberish. --- usr.bin/top/machine.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'usr.bin/top') diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index c39d5476d292..6aabe8adf41f 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -19,7 +19,7 @@ * Steven Wallace * Wolfram Schneider * - * $Id: machine.c,v 1.19 1999/01/22 11:09:41 dillon Exp $ + * $Id: machine.c,v 1.20 1999/02/06 06:33:55 dillon Exp $ */ @@ -547,6 +547,7 @@ char *(*get_userid)(); register double pct; struct handle *hp; char status[16]; + int state; /* find and remember the next proc structure */ hp = (struct handle *)handle; @@ -581,7 +582,7 @@ char *(*get_userid)(); pct = pctdouble(PP(pp, p_pctcpu)); /* generate "STATE" field */ - switch (PP(pp, p_stat)) { + switch (state = PP(pp, p_stat)) { case SRUN: if (smpmode && PP(pp, p_oncpu) >= 0) sprintf(status, "CPU%d", PP(pp, p_oncpu)); @@ -595,7 +596,12 @@ char *(*get_userid)(); } /* fall through */ default: - sprintf(status, "%.6s", state_abbrev[(unsigned char) PP(pp, p_stat)]); + + if (state >= 0 && + state < sizeof(state_abbrev) / sizeof(*state_abbrev)) + sprintf(status, "%.6s", state_abbrev[(unsigned char) state]); + else + sprintf(status, "?%5d", state); break; } -- cgit v1.2.3