realloc pedant

This commit is contained in:
itojun 2003-09-19 06:11:35 +00:00
parent 0c4a8b5a7e
commit e99b62a1d7
5 changed files with 31 additions and 21 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ac.c,v 1.15 2003/05/17 18:55:18 itojun Exp $ */
/* $NetBSD: ac.c,v 1.16 2003/09/19 06:19:02 itojun Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@ -49,7 +49,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ac.c,v 1.15 2003/05/17 18:55:18 itojun Exp $");
__RCSID("$NetBSD: ac.c,v 1.16 2003/09/19 06:19:02 itojun Exp $");
#endif
#include <sys/types.h>
@ -224,6 +224,7 @@ static void
find_login_ttys()
{
struct ttyent *tty;
char (*nCon)[UT_LINESIZE];
if ((Con = malloc((Maxcon = 10) * sizeof(Con[0]))) == NULL)
err(1, "malloc");
@ -232,10 +233,13 @@ find_login_ttys()
while ((tty = getttyent()) != NULL)
if ((tty->ty_status & TTY_ON) != 0 &&
strstr(tty->ty_getty, "getty") != NULL) {
if (Ncon == Maxcon)
if ((Con = realloc(Con, (Maxcon += 10) *
if (Ncon == Maxcon) {
if ((nCon = realloc(Con, (Maxcon + 10) *
sizeof(Con[0]))) == NULL)
err(1, "malloc");
Con = nCon;
Maxcon += 10;
}
(void)strncpy(Con[Ncon++], tty->ty_name, UT_LINESIZE);
}
endttyent();

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.17 2003/08/07 11:25:17 agc Exp $ */
/* $NetBSD: util.c,v 1.18 2003/09/19 06:19:56 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -76,9 +76,11 @@ emalloc(size_t size)
void *
erealloc(void *p, size_t size)
{
void *q;
if ((p = realloc(p, size)) == NULL)
if ((q = realloc(p, size)) == NULL)
nomem();
p = q;
return (p);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs.c,v 1.22 2003/09/07 14:24:08 fvdl Exp $ */
/* $NetBSD: ffs.c,v 1.23 2003/09/19 06:11:35 itojun Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -67,7 +67,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: ffs.c,v 1.22 2003/09/07 14:24:08 fvdl Exp $");
__RCSID("$NetBSD: ffs.c,v 1.23 2003/09/19 06:11:35 itojun Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -918,6 +918,7 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
{
struct direct de, *dp;
uint16_t llen, reclen;
char *newbuf;
assert (dbuf != NULL);
assert (name != NULL);
@ -945,12 +946,13 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
de.d_namlen, de.d_name);
if (reclen + dbuf->cur + llen > roundup(dbuf->size, DIRBLKSIZ)) {
dbuf->size += DIRBLKSIZ; /* need another chunk */
if (debug & DEBUG_FS_MAKE_DIRBUF)
printf("ffs_make_dirbuf: growing buf to %d\n",
dbuf->size);
if ((dbuf->buf = realloc(dbuf->buf, dbuf->size)) == NULL)
dbuf->size + DIRBLKSIZ);
if ((newbuf = realloc(dbuf->buf, dbuf->size + DIRBLKSIZ)) == NULL)
err(1, "Allocating memory for directory buffer");
dbuf->buf = newbuf;
dbuf->size += DIRBLKSIZ;
memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ);
dbuf->cur = dbuf->size - DIRBLKSIZ;
} else { /* shrink end of previous */

View File

@ -1,4 +1,4 @@
/* $NetBSD: walk.c,v 1.14 2003/08/07 11:25:32 agc Exp $ */
/* $NetBSD: walk.c,v 1.15 2003/09/19 06:11:35 itojun Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -73,7 +73,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: walk.c,v 1.14 2003/08/07 11:25:32 agc Exp $");
__RCSID("$NetBSD: walk.c,v 1.15 2003/09/19 06:11:35 itojun Exp $");
#endif /* !__lint */
#include <sys/param.h>
@ -497,7 +497,7 @@ link_check(fsinode *entry)
uint32_t dev;
uint32_t ino;
fsinode *dup;
} *dups;
} *dups, *newdups;
static int ndups, maxdups;
int i;
@ -519,10 +519,11 @@ link_check(fsinode *entry)
printf("link_check: no match for [%d, %d]\n",
entry->st.st_dev, entry->st.st_ino);
if (ndups == maxdups) {
maxdups += 128;
if ((dups = realloc(dups, sizeof(struct dupnode) * maxdups))
if ((newdups = realloc(dups, sizeof(struct dupnode) * (maxdups + 128)))
== NULL)
err(1, "Memory allocation error");
dups = newdups;
maxdups += 128;
}
dups[ndups].dev = entry->st.st_dev;
dups[ndups].ino = entry->st.st_ino;

View File

@ -1,4 +1,4 @@
/* $NetBSD: spec.c,v 1.50 2003/08/07 11:25:36 agc Exp $ */
/* $NetBSD: spec.c,v 1.51 2003/09/19 06:15:55 itojun Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: spec.c,v 1.50 2003/08/07 11:25:36 agc Exp $");
__RCSID("$NetBSD: spec.c,v 1.51 2003/09/19 06:15:55 itojun Exp $");
#endif
#endif /* not lint */
@ -104,7 +104,7 @@ spec(FILE *fp)
NODE *centry, *last, *pathparent, *cur;
char *p, *e, *next;
NODE ginfo, *root;
char *buf, *tname;
char *buf, *tname, *ntname;
size_t tnamelen, plen;
root = NULL;
@ -162,9 +162,10 @@ noparent: mtree_err("no parent node");
plen = strlen(p) + 1;
if (plen > tnamelen) {
tnamelen = plen;
if ((tname = realloc(tname, tnamelen)) == NULL)
if ((ntname = realloc(tname, plen)) == NULL)
mtree_err("realloc: %s", strerror(errno));
tname = ntname;
tnamelen = plen;
}
if (strunvis(tname, p) == -1)
mtree_err("strunvis failed on `%s'", p);