summaryrefslogtreecommitdiff
path: root/usr.bin/pcc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2007-09-17 07:40:07 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2007-09-17 07:40:07 +0000
commite2265c677eef539f951f3bc828f691a00257219e (patch)
tree4ca21b4259cf6a390a4b32c92c2c64c1699ef1ee /usr.bin/pcc
parent383ca7837339b95d8df7bda0367ad5f6f56f3c89 (diff)
checked malloc/calloc calls. from ragge's repo, originally from Stefan
Kempf.
Diffstat (limited to 'usr.bin/pcc')
-rw-r--r--usr.bin/pcc/cc/cc/cc.c13
-rw-r--r--usr.bin/pcc/cc/cpp/cpp.c16
-rw-r--r--usr.bin/pcc/mip/common.c5
3 files changed, 21 insertions, 13 deletions
diff --git a/usr.bin/pcc/cc/cc/cc.c b/usr.bin/pcc/cc/cc/cc.c
index 3685dcf6faf..a49659ff4e9 100644
--- a/usr.bin/pcc/cc/cc/cc.c
+++ b/usr.bin/pcc/cc/cc/cc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cc.c,v 1.3 2007/09/16 18:44:56 otto Exp $ */
+/* $OpenBSD: cc.c,v 1.4 2007/09/17 07:40:06 otto Exp $ */
/*
* Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
*
@@ -605,9 +605,10 @@ setsuf(char *s, char ch)
}
int
-callsys(f, v)
-char f[], *v[]; {
- int t, status;
+callsys(char f[], char *v[])
+{
+ int status;
+ pid_t t;
char *s;
if (vflag) {
@@ -619,8 +620,10 @@ char f[], *v[]; {
if ((t=fork())==0) {
if (Bflag) {
- int len = strlen(Bflag) + 8;
+ size_t len = strlen(Bflag) + 8;
char *a = malloc(len);
+ if (a == NULL)
+ errorx(1, "callsys: malloc failed\n");
if ((s = strrchr(f, '/'))) {
strlcpy(a, Bflag, len);
strlcat(a, s, len);
diff --git a/usr.bin/pcc/cc/cpp/cpp.c b/usr.bin/pcc/cc/cpp/cpp.c
index 12d77bfb8c9..7441c49d893 100644
--- a/usr.bin/pcc/cc/cpp/cpp.c
+++ b/usr.bin/pcc/cc/cpp/cpp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpp.c,v 1.3 2007/09/16 18:52:52 otto Exp $ */
+/* $Id: cpp.c,v 1.4 2007/09/17 07:40:06 otto Exp $ */
/*
* Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
@@ -186,7 +186,9 @@ main(int argc, char **argv)
case 'i': /* include */
case 'U': /* undef */
case 'D': /* define something */
- it = malloc(sizeof(struct initar));
+ /* XXX should not need malloc() here */
+ if ((it = malloc(sizeof(struct initar))) == NULL)
+ error("couldn't apply -%c %s", ch, optarg);
it->type = ch;
it->str = optarg;
it->next = initar;
@@ -223,7 +225,8 @@ main(int argc, char **argv)
case 'S':
case 'I':
- w = calloc(sizeof(struct incs), 1);
+ if ((w = calloc(sizeof(struct incs), 1)) == NULL)
+ error("couldn't apply -%c %s", ch, optarg);
w->dir = (usch *)optarg;
w2 = incdir[ch == 'I' ? INCINC : SYSINC];
if (w2 != NULL) {
@@ -1324,8 +1327,6 @@ struct tree {
static struct tree *sympole;
static int numsyms;
-#define getree() malloc(sizeof(struct tree))
-
/*
* Allocate a symtab struct and store the string.
*/
@@ -1334,6 +1335,8 @@ getsymtab(usch *str)
{
struct symtab *sp = malloc(sizeof(struct symtab));
+ if (sp == NULL)
+ error("getsymtab: couldn't allocate symtab");
sp->namep = savstr(str);
savch('\0');
sp->value = NULL;
@@ -1407,7 +1410,8 @@ lookup(usch *key, int enterf)
ix >>= 1, cix++;
/* Create new node */
- new = getree();
+ if ((new = malloc(sizeof *new)) == NULL)
+ error("getree: couldn't allocate tree");
bit = P_BIT(key, cix);
new->bitno = cix | (bit ? RIGHT_IS_LEAF : LEFT_IS_LEAF);
new->lr[bit] = (struct tree *)getsymtab(key);
diff --git a/usr.bin/pcc/mip/common.c b/usr.bin/pcc/mip/common.c
index d66d963ac73..0f8e88cbf28 100644
--- a/usr.bin/pcc/mip/common.c
+++ b/usr.bin/pcc/mip/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.3 2007/09/16 18:52:52 otto Exp $ */
+/* $OpenBSD: common.c,v 1.4 2007/09/17 07:40:06 otto Exp $ */
/*
* Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -514,7 +514,8 @@ tmpalloc(int size)
void *rv;
if (size > MEMCHUNKSZ) {
- return malloc(size);
+ if ((rv = malloc(size)) == NULL)
+ cerror("tmpalloc: out of memory");
// cerror("tmpalloc %d", size);
}
if (size <= 0)