Module Name: src
Committed By: dholland
Date: Sat May 9 23:16:51 UTC 2015
Modified Files:
src/usr.bin/rpcgen: rpc_cout.c rpc_util.c
Log Message:
Use errx when malloc fails, and also don't cast the return value of
malloc/realloc.
To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/rpcgen/rpc_cout.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/rpcgen/rpc_util.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/rpcgen/rpc_cout.c
diff -u src/usr.bin/rpcgen/rpc_cout.c:1.35 src/usr.bin/rpcgen/rpc_cout.c:1.36
--- src/usr.bin/rpcgen/rpc_cout.c:1.35 Sat May 9 23:14:22 2015
+++ src/usr.bin/rpcgen/rpc_cout.c Sat May 9 23:16:51 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: rpc_cout.c,v 1.35 2015/05/09 23:14:22 dholland Exp $ */
+/* $NetBSD: rpc_cout.c,v 1.36 2015/05/09 23:16:51 dholland Exp $ */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI";
#else
-__RCSID("$NetBSD: rpc_cout.c,v 1.35 2015/05/09 23:14:22 dholland Exp $");
+__RCSID("$NetBSD: rpc_cout.c,v 1.36 2015/05/09 23:16:51 dholland Exp $");
#endif
#endif
@@ -476,7 +476,7 @@ emit_struct(definition *def)
else {
char *nsizestr;
- nsizestr = (char *) realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1);
+ nsizestr = realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1);
if (nsizestr == NULL) {
errx(EXIT_FAILURE, "Out of memory");
@@ -711,11 +711,10 @@ upcase(const char *str)
char *ptr, *hptr;
- ptr = (char *) malloc(strlen(str) + 1);
+ ptr = malloc(strlen(str) + 1);
if (ptr == NULL) {
- f_print(stderr, "malloc failed\n");
- exit(1);
- };
+ errx(EXIT_FAILURE, "Out of memory");
+ }
hptr = ptr;
while (*str != '\0')
Index: src/usr.bin/rpcgen/rpc_util.c
diff -u src/usr.bin/rpcgen/rpc_util.c:1.15 src/usr.bin/rpcgen/rpc_util.c:1.16
--- src/usr.bin/rpcgen/rpc_util.c:1.15 Sat May 9 23:12:57 2015
+++ src/usr.bin/rpcgen/rpc_util.c Sat May 9 23:16:51 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: rpc_util.c,v 1.15 2015/05/09 23:12:57 dholland Exp $ */
+/* $NetBSD: rpc_util.c,v 1.16 2015/05/09 23:16:51 dholland Exp $ */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
#else
-__RCSID("$NetBSD: rpc_util.c,v 1.15 2015/05/09 23:12:57 dholland Exp $");
+__RCSID("$NetBSD: rpc_util.c,v 1.16 2015/05/09 23:16:51 dholland Exp $");
#endif
#endif
@@ -432,8 +432,7 @@ make_argname(const char *pname, const ch
len = strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3;
name = malloc(len);
if (!name) {
- fprintf(stderr, "failed in malloc");
- exit(1);
+ errx(EXIT_FAILURE, "Out of memory");
}
snprintf(name, len, "%s_%s_%s", locase(pname), vname, ARGEXT);
return (name);
@@ -448,8 +447,7 @@ add_type(int len, const char *type)
bas_type *ptr;
if ((ptr = malloc(sizeof(bas_type))) == NULL) {
- fprintf(stderr, "failed in malloc");
- exit(1);
+ errx(EXIT_FAILURE, "Out of memory");
}
ptr->name = type;
ptr->length = len;