summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-07-04 02:38:59 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-07-04 02:38:59 +0000
commit42fa94d17d8074f808122d9412cf257dac4d71aa (patch)
tree245c5ddeaedcd98bbf5e5257c003c4e7e4dc0362
parent92809e364832a1206235fddb4b3432bda0b1d3c6 (diff)
catch malloc failures, my changes; found by cloder@acm.org
-rw-r--r--usr.bin/awk/lib.c4
-rw-r--r--usr.bin/awk/maketab.c18
2 files changed, 14 insertions, 8 deletions
diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c
index 24bbf169489..2e2ec08b547 100644
--- a/usr.bin/awk/lib.c
+++ b/usr.bin/awk/lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib.c,v 1.9 2001/11/05 09:58:13 deraadt Exp $ */
+/* $OpenBSD: lib.c,v 1.10 2002/07/04 02:38:58 deraadt Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -66,6 +66,8 @@ void recinit(unsigned int n)
FATAL("out of space for $0 and fields");
fldtab[0] = (Cell *) malloc(sizeof (Cell));
+ if (fldtab[0] == NULL)
+ FATAL("out of space for fields");
*fldtab[0] = dollar0;
fldtab[0]->sval = record;
fldtab[0]->nval = tostring("0");
diff --git a/usr.bin/awk/maketab.c b/usr.bin/awk/maketab.c
index 9cafbc7d2a1..84e3db99566 100644
--- a/usr.bin/awk/maketab.c
+++ b/usr.bin/awk/maketab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: maketab.c,v 1.4 2001/09/08 00:12:40 millert Exp $ */
+/* $OpenBSD: maketab.c,v 1.5 2002/07/04 02:38:58 deraadt Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -126,21 +126,25 @@ int main(int argc, char *argv[])
names[i] = "";
if ((fp = fopen("ytab.h", "r")) == NULL) {
- fprintf(stderr, "maketab can't open ytab.h!\n");
+ fprintf(stderr, "maketab: can't open ytab.h!\n");
exit(1);
}
printf("static char *printname[%d] = {\n", SIZE);
i = 0;
while (fgets(buf, sizeof buf, fp) != NULL) {
n = sscanf(buf, "%1c %s %s %d", &c, def, name, &tok);
- if (c != '#' || (n != 4 && strcmp(def,"define") != 0)) /* not a valid #define */
- continue;
+ if (c != '#' || (n != 4 && strcmp(def,"define") != 0))
+ continue; /* not a valid #define */
if (tok < FIRSTTOKEN || tok > LASTTOKEN) {
- fprintf(stderr, "maketab funny token %d %s ignored\n", tok, buf);
+ fprintf(stderr, "maketab: funny token %d %s ignored\n",
+ tok, buf);
continue;
}
- names[tok-FIRSTTOKEN] = (char *) malloc(strlen(name)+1);
- strcpy(names[tok-FIRSTTOKEN], name);
+ names[tok-FIRSTTOKEN] = (char *) strdup(name);
+ if (names[tok-FIRSTTOKEN] == NULL) {
+ fprintf(stderr, "maketab: out of memory\n");
+ exit(1);
+ }
printf("\t(char *) \"%s\",\t/* %d */\n", name, tok);
i++;
}