Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/hunt/hunt huntd(6): convert malloc(x * y) and realloc(...



details:   https://anonhg.NetBSD.org/src/rev/77fd934761c9
branches:  trunk
changeset: 1024581:77fd934761c9
user:      nia <nia%NetBSD.org@localhost>
date:      Fri Oct 29 11:40:23 2021 +0000

description:
huntd(6): convert malloc(x * y) and realloc(x * y) to reallocarr

diffstat:

 games/hunt/hunt/server.c |  18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)

diffs (56 lines):

diff -r e2c3d60eb0bf -r 77fd934761c9 games/hunt/hunt/server.c
--- a/games/hunt/hunt/server.c  Fri Oct 29 11:03:46 2021 +0000
+++ b/games/hunt/hunt/server.c  Fri Oct 29 11:40:23 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: server.c,v 1.8 2014/03/30 04:57:37 dholland Exp $      */
+/*     $NetBSD: server.c,v 1.9 2021/10/29 11:40:23 nia Exp $   */
 /*
  * Copyright (c) 1983-2003, Regents of the University of California.
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: server.c,v 1.8 2014/03/30 04:57:37 dholland Exp $");
+__RCSID("$NetBSD: server.c,v 1.9 2021/10/29 11:40:23 nia Exp $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -85,10 +85,9 @@
 
        numdaemons = 0;
        maxdaemons = 20;
-       daemons = malloc(maxdaemons * sizeof(daemons[0]));
-       if (daemons == NULL) {
+       daemons = NULL;
+       if (reallocarr(&daemons, maxdaemons, sizeof(daemons[0])) != 0)
                leavex(1, "Out of memory.");
-       }
 
        if (explicit_host_arg) {
                explicit_host = explicit_host_arg;
@@ -111,10 +110,8 @@
        assert(numdaemons <= maxdaemons);
        if (numdaemons == maxdaemons) {
                maxdaemons += 20;
-               daemons = realloc(daemons, maxdaemons * sizeof(daemons[0]));
-               if (daemons == NULL) {
+               if (reallocarr(&daemons, maxdaemons, sizeof(daemons[0])) != 0)
                        leave(1, "realloc");
-               }
        }
 
        /*
@@ -181,10 +178,9 @@
                }
        }
 
-       broadcastaddrs = malloc(num * sizeof(broadcastaddrs[0]));
-       if (broadcastaddrs == NULL) {
+       broadcastaddrs = NULL;
+       if (reallocarr(&broadcastaddrs, num, sizeof(broadcastaddrs[0])) != 0)
                leavex(1, "Out of memory");
-       }
 
        i = 0;
        for (ip = ifp; ip; ip = ip->ifa_next) {



Home | Main Index | Thread Index | Old Index