summaryrefslogtreecommitdiff
path: root/status.c
diff options
context:
space:
mode:
authortgoodwin <tgoodwin>1998-07-20 10:12:46 +0000
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:23:09 +0100
commit096de180211a0573a80d9380aae99b940ce46a42 (patch)
tree7c0bb40d28f65e6be3ff0aa092f91fe293ae8200 /status.c
parent7203d4edba0affd77b257610a2fa6e23a37a8da6 (diff)
only call WTERMSIG if WIFSIGNALED
also, always check that WTERMSIG is in range
Diffstat (limited to 'status.c')
-rw-r--r--status.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/status.c b/status.c
index 882e506..8926000 100644
--- a/status.c
+++ b/status.c
@@ -64,7 +64,8 @@ extern void setstatus(pid_t pid, int i) {
extern void statprint(pid_t pid, int i) {
if (WIFSIGNALED(i)) {
- char *msg = (WTERMSIG(i) < NUMOFSIGNALS ? signals[WTERMSIG(i)].msg : "");
+ int t = WTERMSIG(i);
+ char *msg = ((t > 0) && (t < NUMOFSIGNALS) ? signals[WTERMSIG(i)].msg : "");
if (pid != -1)
fprint(2, "%ld: ", (long)pid);
if (myWIFDUMPED(i)) {
@@ -99,11 +100,10 @@ extern List *sgetstatus() {
/* return status as a string (used above and for bqstatus) */
extern char *strstatus(int s) {
- int t = WTERMSIG(s);
-
- if (t != 0) {
+ if (WIFSIGNALED(s)) {
+ int t = WTERMSIG(s);
const char *core = myWIFDUMPED(s) ? "+core" : "";
- if (t < NUMOFSIGNALS && *signals[t].name != '\0')
+ if ((t > 0) && (t < NUMOFSIGNALS) && *signals[t].name != '\0')
return nprint("%s%s", signals[t].name, core);
else
return nprint("-%d%s", t, core); /* unknown signals are negated */