diff options
author | Bill Fenner <fenner@FreeBSD.org> | 1999-02-06 16:58:50 +0000 |
---|---|---|
committer | Bill Fenner <fenner@FreeBSD.org> | 1999-02-06 16:58:50 +0000 |
commit | 1005b43609bd5bd55eca1278cf762eb59702a1a1 (patch) | |
tree | aac5ea6b4f258a182001032ba66ce7113c219b27 /usr.bin/top | |
parent | 76744f75ab78ff652cf4e8fd7ee1b7d82e44b5ed (diff) | |
download | src-1005b43609bd5bd55eca1278cf762eb59702a1a1.tar.gz src-1005b43609bd5bd55eca1278cf762eb59702a1a1.zip |
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.
Notes
Notes:
svn path=/head/; revision=43720
Diffstat (limited to 'usr.bin/top')
-rw-r--r-- | usr.bin/top/machine.c | 12 |
1 files changed, 9 insertions, 3 deletions
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 <swallace@freebsd.org> * Wolfram Schneider <wosch@FreeBSD.org> * - * $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; } |