Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/ypcat ypcat(1): Convert realloc(x * y) to reallocarr.
details: https://anonhg.NetBSD.org/src/rev/e88fe5a889a1
branches: trunk
changeset: 990540:e88fe5a889a1
user: nia <nia%NetBSD.org@localhost>
date: Sat Oct 30 08:56:54 2021 +0000
description:
ypcat(1): Convert realloc(x * y) to reallocarr.
We can eliminate a temporary variable here too.
diffstat:
usr.bin/ypcat/ypalias_init.c | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
diffs (67 lines):
diff -r c57ab615ce22 -r e88fe5a889a1 usr.bin/ypcat/ypalias_init.c
--- a/usr.bin/ypcat/ypalias_init.c Sat Oct 30 08:20:35 2021 +0000
+++ b/usr.bin/ypcat/ypalias_init.c Sat Oct 30 08:56:54 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ypalias_init.c,v 1.1 2009/06/20 19:27:26 christos Exp $ */
+/* $NetBSD: ypalias_init.c,v 1.2 2021/10/30 08:56:54 nia Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ypalias_init.c,v 1.1 2009/06/20 19:27:26 christos Exp $");
+__RCSID("$NetBSD: ypalias_init.c,v 1.2 2021/10/30 08:56:54 nia Exp $");
#endif
#include <err.h>
@@ -69,9 +69,9 @@
{
FILE *fp;
char *cp, *line;
- struct ypalias *ypa, *nypa;
+ struct ypalias *ypa;
size_t nypalias = 50;
- size_t i, len, lineno;
+ size_t i = 0, len, lineno;
if ((fp = fopen(_PATH_YPNICKNAMES, "r")) == NULL)
return &def_ypaliases[0];
@@ -80,7 +80,7 @@
goto out;
lineno = 1;
- for (i = 0; (line = fparseln(fp, &len, &lineno, NULL,
+ for (; (line = fparseln(fp, &len, &lineno, NULL,
FPARSELN_UNESCALL));) {
cp = line;
/* Ignore malformed lines */
@@ -94,18 +94,16 @@
i++;
if (i == nypalias) {
nypalias <<= 1;
- nypa = realloc(ypa, sizeof(*ypa) * nypalias);
- if (nypa == NULL)
+ if (reallocarr(&ypa, nypalias, sizeof(*ypa)) != 0)
goto out;
- ypa = nypa;
}
}
ypa[i].alias = ypa[i].name = NULL;
i++;
(void)fclose(fp);
- if ((nypa = realloc(ypa, sizeof(*ypa) * i)) != NULL)
- return nypa;
+ if (reallocarr(&ypa, i, sizeof(*ypa)) == 0)
+ return ypa;
out:
warn("Cannot alllocate alias space, returning default list");
if (ypa) {
@@ -116,5 +114,4 @@
}
(void)fclose(fp);
return def_ypaliases;
- return ypa;
}
Home |
Main Index |
Thread Index |
Old Index