Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/join join(1): convert realloc(x * y) to reallocarr a...



details:   https://anonhg.NetBSD.org/src/rev/4c32a608131e
branches:  trunk
changeset: 990679:4c32a608131e
user:      nia <nia%NetBSD.org@localhost>
date:      Tue Nov 02 10:05:49 2021 +0000

description:
join(1): convert realloc(x * y) to reallocarr and eliminate temporary
variables

diffstat:

 usr.bin/join/join.c |  22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diffs (78 lines):

diff -r f00f80e6512a -r 4c32a608131e usr.bin/join/join.c
--- a/usr.bin/join/join.c       Tue Nov 02 08:39:20 2021 +0000
+++ b/usr.bin/join/join.c       Tue Nov 02 10:05:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: join.c,v 1.33 2021/03/18 19:47:41 cheusov Exp $        */
+/*     $NetBSD: join.c,v 1.34 2021/11/02 10:05:49 nia Exp $    */
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -47,7 +47,7 @@
 #if 0
 static char sccsid[] = "from: @(#)join.c       5.1 (Berkeley) 11/18/91";
 #else
-__RCSID("$NetBSD: join.c,v 1.33 2021/03/18 19:47:41 cheusov Exp $");
+__RCSID("$NetBSD: join.c,v 1.34 2021/11/02 10:05:49 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -301,7 +301,6 @@
 {
        LINE *lp;
        LINE tmp;
-       LINE *nline;
        size_t len;
        u_long cnt;
        char *bp, *fieldp;
@@ -323,10 +322,8 @@
                                nsize = 64;
                        else
                                nsize = F->setalloc << 1;
-                       if ((nline = realloc(F->set,
-                           nsize * sizeof(LINE))) == NULL)
+                       if (reallocarr(&F->set, nsize, sizeof(LINE)) != 0)
                                enomem();
-                       F->set = nline;
                        F->setalloc = nsize;
                        memset(F->set + cnt, 0,
                            (F->setalloc - cnt) * sizeof(LINE));
@@ -379,16 +376,13 @@
                        if (spans && *fieldp == '\0')
                                continue;
                        if (lp->fieldcnt == lp->fieldalloc) {
-                               char **n;
-
                                if (lp->fieldalloc == 0)
                                        nsize = 16;
                                else
                                        nsize = lp->fieldalloc << 1;
-                               if ((n = realloc(lp->fields,
-                                   nsize * sizeof(char *))) == NULL)
+                               if (reallocarr(&lp->fields,
+                                   nsize, sizeof(char *)) != 0)
                                        enomem();
-                               lp->fields = n;
                                lp->fieldalloc = nsize;
                        }
                        lp->fields[lp->fieldcnt++] = fieldp;
@@ -518,7 +512,6 @@
 {
        u_long fieldno;
        char *end, *token;
-       OLIST *n;
 
        while ((token = strsep(&option, ", \t")) != NULL) {
                if (*token == '\0')
@@ -531,10 +524,9 @@
                if (fieldno == 0)
                        errx(1, "field numbers are 1 based");
                if (olistcnt == olistalloc) {
-                       if ((n = realloc(olist,
-                           (olistalloc + 50) * sizeof(OLIST))) == NULL)
+                       if (reallocarr(&olist,
+                           olistalloc + 50, sizeof(OLIST)) != 0)
                                enomem();
-                       olist = n;
                        olistalloc += 50;
                }
                olist[olistcnt].fileno = token[0] - '0';



Home | Main Index | Thread Index | Old Index