Module Name: src
Committed By: nia
Date: Sat Mar 12 08:41:38 UTC 2022
Modified Files:
src/lib/libc/net: getprotoent_r.c
Log Message:
getprotoent_r: use reallocarr
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/net/getprotoent_r.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/net/getprotoent_r.c
diff -u src/lib/libc/net/getprotoent_r.c:1.6 src/lib/libc/net/getprotoent_r.c:1.7
--- src/lib/libc/net/getprotoent_r.c:1.6 Sat Oct 15 23:00:02 2011
+++ src/lib/libc/net/getprotoent_r.c Sat Mar 12 08:41:38 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: getprotoent_r.c,v 1.6 2011/10/15 23:00:02 christos Exp $ */
+/* $NetBSD: getprotoent_r.c,v 1.7 2022/03/12 08:41:38 nia Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: getprotoent_r.c,v 1.6 2011/10/15 23:00:02 christos Exp $");
+__RCSID("$NetBSD: getprotoent_r.c,v 1.7 2022/03/12 08:41:38 nia Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -87,7 +87,6 @@ getprotoent_r(struct protoent *pr, struc
{
char *p, *cp, **q;
size_t i = 0;
- int oerrno;
if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "re")) == NULL)
return NULL;
@@ -111,12 +110,12 @@ getprotoent_r(struct protoent *pr, struc
*p++ = '\0';
pr->p_proto = atoi(cp);
if (pd->aliases == NULL) {
+ pd->aliases = NULL;
pd->maxaliases = 10;
- pd->aliases = malloc(pd->maxaliases * sizeof(char *));
- if (pd->aliases == NULL) {
- oerrno = errno;
+ if (reallocarr(&pd->aliases,
+ pd->maxaliases, sizeof(char *)) != 0) {
endprotoent_r(pd);
- errno = oerrno;
+ errno = ENOMEM;
return NULL;
}
}
@@ -130,12 +129,10 @@ getprotoent_r(struct protoent *pr, struc
}
if (i == pd->maxaliases - 2) {
pd->maxaliases *= 2;
- q = realloc(q,
- pd->maxaliases * sizeof(char *));
- if (q == NULL) {
- oerrno = errno;
+ if (reallocarr(&q,
+ pd->maxaliases, sizeof(char *)) != 0) {
endprotoent_r(pd);
- errno = oerrno;
+ errno = ENOMEM;
return NULL;
}
pr->p_aliases = pd->aliases = q;