Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librefuse refuse(3): Simplify reallocation logic with re...
details: https://anonhg.NetBSD.org/src/rev/0e2914bccda0
branches: trunk
changeset: 990541:0e2914bccda0
user: nia <nia%NetBSD.org@localhost>
date: Sat Oct 30 09:06:34 2021 +0000
description:
refuse(3): Simplify reallocation logic with reallocarr.
diffstat:
lib/librefuse/refuse_opt.c | 12 +++---------
1 files changed, 3 insertions(+), 9 deletions(-)
diffs (48 lines):
diff -r e88fe5a889a1 -r 0e2914bccda0 lib/librefuse/refuse_opt.c
--- a/lib/librefuse/refuse_opt.c Sat Oct 30 08:56:54 2021 +0000
+++ b/lib/librefuse/refuse_opt.c Sat Oct 30 09:06:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: refuse_opt.c,v 1.18 2016/11/16 16:11:42 pho Exp $ */
+/* $NetBSD: refuse_opt.c,v 1.19 2021/10/30 09:06:34 nia Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@@ -58,13 +58,11 @@
args->allocated = ap->allocated;
(void) free(ap);
} else if (args->allocated == args->argc) {
- void *a;
int na = args->allocated + 10;
- if ((a = realloc(args->argv, na * sizeof(*args->argv))) == NULL)
+ if (reallocarr(&args->argv, na, sizeof(*args->argv)) != 0)
return -1;
- args->argv = a;
args->allocated = na;
}
DPRINTF(("%s: arguments passed: [arg:%s]\n", __func__, arg));
@@ -119,22 +117,18 @@
{
int i;
int na;
- void *a;
DPRINTF(("%s: arguments passed: [pos=%d] [arg=%s]\n",
__func__, pos, arg));
if (args->argv == NULL) {
na = 10;
- a = malloc(na * sizeof(*args->argv));
} else {
na = args->allocated + 10;
- a = realloc(args->argv, na * sizeof(*args->argv));
}
- if (a == NULL) {
+ if (reallocarr(&args->argv, na, sizeof(*args->argv)) != 0) {
warn("fuse_opt_insert_arg");
return -1;
}
- args->argv = a;
args->allocated = na;
for (i = args->argc++; i > pos; --i) {
Home |
Main Index |
Thread Index |
Old Index