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

variables
This commit is contained in:
nia 2021-11-02 10:05:49 +00:00
parent 464e94c8b5
commit 66fcf23d5d
1 changed files with 7 additions and 15 deletions

View File

@ -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';