Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/systat netstat(1): use reallocarr instead of realloc...
details: https://anonhg.NetBSD.org/src/rev/59c54b179298
branches: trunk
changeset: 1024643:59c54b179298
user: nia <nia%NetBSD.org@localhost>
date: Sat Oct 30 11:31:51 2021 +0000
description:
netstat(1): use reallocarr instead of realloc(x * y)
diffstat:
usr.bin/systat/netcmds.c | 12 ++++--------
1 files changed, 4 insertions(+), 8 deletions(-)
diffs (46 lines):
diff -r b4429e47c8c4 -r 59c54b179298 usr.bin/systat/netcmds.c
--- a/usr.bin/systat/netcmds.c Sat Oct 30 11:25:30 2021 +0000
+++ b/usr.bin/systat/netcmds.c Sat Oct 30 11:31:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netcmds.c,v 1.21 2005/02/26 22:12:33 dsl Exp $ */
+/* $NetBSD: netcmds.c,v 1.22 2021/10/30 11:31:51 nia Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)netcmds.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: netcmds.c,v 1.21 2005/02/26 22:12:33 dsl Exp $");
+__RCSID("$NetBSD: netcmds.c,v 1.22 2021/10/30 11:31:51 nia Exp $");
#endif /* not lint */
/*
@@ -223,12 +223,10 @@
p->onoff = onoff;
return (0);
}
- p = (struct pitem *)realloc(ports, (nports+1)*sizeof (*p));
- if (p == NULL) {
+ if (reallocarr(&ports, nports + 1, sizeof(*p)) != 0) {
error("malloc failed");
die(0);
}
- ports = p;
p = &ports[nports++];
p->port = port;
p->onoff = onoff;
@@ -326,12 +324,10 @@
}
if (sa->sa_len > sizeof(struct sockaddr_storage))
return (-1); /*XXX*/
- p = (struct hitem *)realloc(hosts, (nhosts+1)*sizeof (*p));
- if (p == NULL) {
+ if (reallocarr(&hosts, nhosts + 1, sizeof(*p)) != 0) {
error("malloc failed");
die(0);
}
- hosts = p;
p = &hosts[nhosts++];
memcpy(&p->addr, sa, sa->sa_len);
p->onoff = onoff;
Home |
Main Index |
Thread Index |
Old Index