summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>1999-02-06 16:58:50 +0000
committerfenner <fenner@FreeBSD.org>1999-02-06 16:58:50 +0000
commit0ed6b55b80a3c586dcb7b0f591427a72f54f6046 (patch)
tree17b72d030a5b3fa02cf4dcb8d68f1bf8e678a189 /usr.bin
parent4b9b97c3b93c4877723941e9ee249c7e412207ee (diff)
downloadFreeBSD-src-0ed6b55b80a3c586dcb7b0f591427a72f54f6046.zip
FreeBSD-src-0ed6b55b80a3c586dcb7b0f591427a72f54f6046.tar.gz
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.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/top/machine.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index c39d547..6aabe8a 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;
}
OpenPOWER on IntegriCloud