Module Name: src Committed By: nia Date: Tue Nov 2 10:05:49 UTC 2021
Modified Files: src/usr.bin/join: join.c Log Message: join(1): convert realloc(x * y) to reallocarr and eliminate temporary variables To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/usr.bin/join/join.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/join/join.c diff -u src/usr.bin/join/join.c:1.33 src/usr.bin/join/join.c:1.34 --- src/usr.bin/join/join.c:1.33 Thu Mar 18 19:47:41 2021 +++ src/usr.bin/join/join.c Tue Nov 2 10:05:49 2021 @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1991\ #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 @@ slurp(INPUT *F) { LINE *lp; LINE tmp; - LINE *nline; size_t len; u_long cnt; char *bp, *fieldp; @@ -323,10 +322,8 @@ slurp(INPUT *F) 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 @@ slurp(INPUT *F) 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 @@ fieldarg(char *option) { u_long fieldno; char *end, *token; - OLIST *n; while ((token = strsep(&option, ", \t")) != NULL) { if (*token == '\0') @@ -531,10 +524,9 @@ fieldarg(char *option) 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';