realloc pedant

This commit is contained in:
itojun 2003-09-19 08:35:15 +00:00
parent dd706c0759
commit 731ae88ecd
5 changed files with 46 additions and 34 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: brconfig.c,v 1.6 2003/06/23 11:53:36 agc Exp $ */ /* $NetBSD: brconfig.c,v 1.7 2003/09/19 08:39:09 itojun Exp $ */
/* /*
* Copyright 2001 Wasabi Systems, Inc. * Copyright 2001 Wasabi Systems, Inc.
@ -43,7 +43,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: brconfig.c,v 1.6 2003/06/23 11:53:36 agc Exp $"); __RCSID("$NetBSD: brconfig.c,v 1.7 2003/09/19 08:39:09 itojun Exp $");
#endif #endif
@ -425,14 +425,15 @@ show_interfaces(int sock, const char *bridge, const char *prefix)
}; };
struct ifbifconf bifc; struct ifbifconf bifc;
struct ifbreq *req; struct ifbreq *req;
char *inbuf = NULL; char *inbuf = NULL, *ninbuf;
int i, len = 8192; int i, len = 8192;
for (;;) { for (;;) {
bifc.ifbic_len = len; ninbuf = realloc(inbuf, len);
bifc.ifbic_buf = inbuf = realloc(inbuf, len); if (ninbuf == NULL)
if (inbuf == NULL)
err(1, "unable to allocate interface buffer"); err(1, "unable to allocate interface buffer");
bifc.ifbic_len = len;
bifc.ifbic_buf = inbuf = ninbuf;
if (do_cmd(sock, bridge, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0) if (do_cmd(sock, bridge, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0)
err(1, "unable to get interface list"); err(1, "unable to get interface list");
if ((bifc.ifbic_len + sizeof(*req)) < len) if ((bifc.ifbic_len + sizeof(*req)) < len)
@ -468,15 +469,16 @@ show_addresses(int sock, const char *bridge, const char *prefix)
{ {
struct ifbaconf ifbac; struct ifbaconf ifbac;
struct ifbareq *ifba; struct ifbareq *ifba;
char *inbuf = NULL; char *inbuf = NULL, *ninbuf;
int i, len = 8192; int i, len = 8192;
struct ether_addr ea; struct ether_addr ea;
for (;;) { for (;;) {
ifbac.ifbac_len = len; ninbuf = realloc(inbuf, len);
ifbac.ifbac_buf = inbuf = realloc(inbuf, len); if (ninbuf == NULL)
if (inbuf == NULL)
err(1, "unable to allocate address buffer"); err(1, "unable to allocate address buffer");
ifbac.ifbac_len = len;
ifbac.ifbac_buf = inbuf = ninbuf;
if (do_cmd(sock, bridge, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0) if (do_cmd(sock, bridge, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0)
err(1, "unable to get address cache"); err(1, "unable to get address cache");
if ((ifbac.ifbac_len + sizeof(*ifba)) < len) if ((ifbac.ifbac_len + sizeof(*ifba)) < len)

View File

@ -1,4 +1,4 @@
/* $NetBSD: ccdconfig.c,v 1.34 2001/02/19 22:56:18 cgd Exp $ */ /* $NetBSD: ccdconfig.c,v 1.35 2003/09/19 08:37:25 itojun Exp $ */
/*- /*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
__COPYRIGHT( __COPYRIGHT(
"@(#) Copyright (c) 1996, 1997\ "@(#) Copyright (c) 1996, 1997\
The NetBSD Foundation, Inc. All rights reserved."); The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: ccdconfig.c,v 1.34 2001/02/19 22:56:18 cgd Exp $"); __RCSID("$NetBSD: ccdconfig.c,v 1.35 2003/09/19 08:37:25 itojun Exp $");
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -330,7 +330,7 @@ do_all(action)
int action; int action;
{ {
FILE *f; FILE *f;
char *line, *cp, *vp, **argv; char *line, *cp, *vp, **argv, **nargv;
int argc, rval; int argc, rval;
size_t len; size_t len;
@ -357,11 +357,13 @@ do_all(action)
if (vp == NULL) if (vp == NULL)
continue; continue;
if ((argv = realloc(argv, if ((nargv = realloc(argv,
sizeof(char *) * ++argc)) == NULL) { sizeof(char *) * (argc + 1))) == NULL) {
warnx("no memory to configure ccds"); warnx("no memory to configure ccds");
return (1); return (1);
} }
argv = nargv;
argc++;
argv[argc - 1] = vp; argv[argc - 1] = vp;
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdisk.c,v 1.69 2003/08/29 16:31:30 dsl Exp $ */ /* $NetBSD: fdisk.c,v 1.70 2003/09/19 08:41:28 itojun Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -35,7 +35,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: fdisk.c,v 1.69 2003/08/29 16:31:30 dsl Exp $"); __RCSID("$NetBSD: fdisk.c,v 1.70 2003/09/19 08:41:28 itojun Exp $");
#endif /* not lint */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
@ -872,6 +872,7 @@ get_extended_ptn(void)
mbr_partition_t *mp; mbr_partition_t *mp;
mbr_sector_t *boot; mbr_sector_t *boot;
daddr_t offset; daddr_t offset;
mbr_sector_t *nptn;
/* find first (there should only be one) extended partition */ /* find first (there should only be one) extended partition */
for (mp = mboot.mbr_parts; !MBR_IS_EXTENDED(mp->mbrp_typ); mp++) for (mp = mboot.mbr_parts; !MBR_IS_EXTENDED(mp->mbrp_typ); mp++)
@ -886,9 +887,10 @@ get_extended_ptn(void)
ext.limit = ext.base + le32toh(mp->mbrp_size); ext.limit = ext.base + le32toh(mp->mbrp_size);
ext.ptn_id = mp - mboot.mbr_parts; ext.ptn_id = mp - mboot.mbr_parts;
for (offset = 0;; offset = le32toh(boot->mbr_parts[1].mbrp_start)) { for (offset = 0;; offset = le32toh(boot->mbr_parts[1].mbrp_start)) {
ext.ptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn); nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn);
if (ext.ptn == NULL) if (nptn == NULL)
err(1, "Malloc failed"); err(1, "Malloc failed");
ext.ptn = nptn;
boot = ext.ptn + ext.num_ptn; boot = ext.ptn + ext.num_ptn;
if (read_s0(offset + ext.base, boot) == -1) if (read_s0(offset + ext.base, boot) == -1)
break; break;
@ -1472,8 +1474,12 @@ add_ext_ptn(daddr_t start, daddr_t size)
{ {
int part; int part;
mbr_partition_t *partp; mbr_partition_t *partp;
mbr_sector_t *nptn;
ext.ptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn); nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn);
if (!nptn)
err(1, "realloc");
ext.ptn = nptn;
for (part = 0; part < ext.num_ptn; part++) for (part = 0; part < ext.num_ptn; part++)
if (ext_offset(part) > start) if (ext_offset(part) > start)
break; break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: inode.c,v 1.40 2003/08/07 10:04:20 agc Exp $ */ /* $NetBSD: inode.c,v 1.41 2003/09/19 08:35:15 itojun Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
#else #else
__RCSID("$NetBSD: inode.c,v 1.40 2003/08/07 10:04:20 agc Exp $"); __RCSID("$NetBSD: inode.c,v 1.41 2003/09/19 08:35:15 itojun Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -483,7 +483,7 @@ cacheino(dp, inumber)
ino_t inumber; ino_t inumber;
{ {
struct inoinfo *inp; struct inoinfo *inp;
struct inoinfo **inpp; struct inoinfo **inpp, **ninpsort;
unsigned int blks; unsigned int blks;
int i; int i;
int64_t size; int64_t size;
@ -515,11 +515,12 @@ cacheino(dp, inumber)
for (i = 0; i < NIADDR; i++) for (i = 0; i < NIADDR; i++)
inp->i_blks[NDADDR + i] = DIP(dp, ib[i]); inp->i_blks[NDADDR + i] = DIP(dp, ib[i]);
if (inplast == listmax) { if (inplast == listmax) {
listmax += 100; ninpsort = (struct inoinfo **)realloc((char *)inpsort,
inpsort = (struct inoinfo **)realloc((char *)inpsort, (unsigned)(listmax + 100) * sizeof(struct inoinfo *));
(unsigned)listmax * sizeof(struct inoinfo *));
if (inpsort == NULL) if (inpsort == NULL)
errx(EEXIT, "cannot increase directory list"); errx(EEXIT, "cannot increase directory list");
inpsort = ninpsort;
listmax += 100;
} }
inpsort[inplast++] = inp; inpsort[inplast++] = inp;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: pass5.c,v 1.37 2003/08/07 10:04:21 agc Exp $ */ /* $NetBSD: pass5.c,v 1.38 2003/09/19 08:35:15 itojun Exp $ */
/* /*
* Copyright (c) 1980, 1986, 1993 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
#else #else
__RCSID("$NetBSD: pass5.c,v 1.37 2003/08/07 10:04:21 agc Exp $"); __RCSID("$NetBSD: pass5.c,v 1.38 2003/09/19 08:35:15 itojun Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -70,8 +70,9 @@ pass5(void)
struct inodesc idesc[4]; struct inodesc idesc[4];
char buf[MAXBSIZE]; char buf[MAXBSIZE];
struct cg *newcg = (struct cg *)buf; struct cg *newcg = (struct cg *)buf;
struct cg *cg = cgrp; struct cg *cg = cgrp, *ncg;
struct inostat *info; struct inostat *info;
u_int32_t ncgsize;
inoinfo(WINO)->ino_state = USTATE; inoinfo(WINO)->ino_state = USTATE;
memset(newcg, 0, (size_t)fs->fs_cgsize); memset(newcg, 0, (size_t)fs->fs_cgsize);
@ -107,13 +108,13 @@ pass5(void)
if (preen) if (preen)
pwarn("%sING CLUSTER MAPS\n", pwarn("%sING CLUSTER MAPS\n",
doit); doit);
fs->fs_cgsize = ncgsize = fragroundup(fs, CGSIZE(fs));
fragroundup(fs, CGSIZE(fs)); ncg = realloc(cgrp, ncgsize);
cg = cgrp = if (ncg == NULL)
realloc(cgrp, fs->fs_cgsize);
if (cg == NULL)
errx(EEXIT, errx(EEXIT,
"cannot reallocate cg space"); "cannot reallocate cg space");
cg = cgrp = ncg;
fs->fs_cgsize = ncgsize;
doinglevel1 = 1; doinglevel1 = 1;
sbdirty(); sbdirty();
} }