Widen the scope of fmt.c::1.19 and consistently use errx(3) if malloc(3) [or

realloc(3)] happens to fail, everywhere in ps(1).

Discussed with:	bde, charnier (a while ago)

fmt_argv() can no longer return NULL, so don't bother checking.

Submitted by:	bde
This commit is contained in:
Juli Mallett 2002-06-05 18:11:25 +00:00
parent 5af50a7c59
commit 4fa7d7880d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97877
3 changed files with 8 additions and 10 deletions

View File

@ -247,10 +247,10 @@ parsefmt(const char *p)
if (cp == NULL || !(v = findvar(cp)))
continue;
if ((vent = malloc(sizeof(struct varent))) == NULL)
err(1, NULL);
errx(1, "malloc failed");
vent->var = malloc(sizeof(*vent->var));
if (vent->var == NULL)
err(1, NULL);
errx(1, "malloc failed");
memcpy(vent->var, v, sizeof(*vent->var));
vent->next = NULL;
if (vhead == NULL)

View File

@ -108,11 +108,11 @@ command(KINFO *k, VARENT *ve)
}
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
err(1, NULL);
errx(1, "malloc failed");
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
if (k->ki_env) {
if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL)
err(1, NULL);
errx(1, "malloc failed");
strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH);
} else
vis_env = NULL;

View File

@ -311,7 +311,7 @@ main(int argc, char *argv[])
/* XXX - should be cleaner */
if (!all && ttydev == NODEV && pid == -1 && !nuids) {
if ((uids = malloc(sizeof (*uids))) == NULL)
err(1, "malloc");
errx(1, "malloc failed");
nuids = 1;
*uids = getuid();
}
@ -343,7 +343,7 @@ main(int argc, char *argv[])
if ((kp = kvm_getprocs(kd, what, flag, &nentries)) == 0 || nentries < 0)
errx(1, "%s", kvm_geterr(kd));
if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL)
err(1, NULL);
errx(1, "malloc failed");
for (i = nentries; --i >= 0; ++kp) {
kinfo[i].ki_p = kp;
if (needuser)
@ -424,7 +424,7 @@ getuids(const char *arg, int *nuids)
moreuids = realloc(uids, alloc * sizeof (*uids));
if (moreuids == NULL) {
free(uids);
err(1, "realloc");
errx(1, "realloc failed");
}
uids = moreuids;
}
@ -500,8 +500,6 @@ fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki,
const char *s;
s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen);
if (s == NULL)
err(1, NULL);
return (s);
}
@ -578,7 +576,7 @@ kludge_oldps_options(char *s)
len = strlen(s);
if ((newopts = ns = malloc(len + 2)) == NULL)
err(1, NULL);
errx(1, "malloc failed");
/*
* options begin with '-'
*/