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.
This commit is contained in:
Bill Fenner 1999-02-06 16:58:50 +00:00
parent 76744f75ab
commit 1005b43609
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=43720

View File

@ -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;
}