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.
@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#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
@ -425,14 +425,15 @@ show_interfaces(int sock, const char *bridge, const char *prefix)
};
struct ifbifconf bifc;
struct ifbreq *req;
char *inbuf = NULL;
char *inbuf = NULL, *ninbuf;
int i, len = 8192;
for (;;) {
bifc.ifbic_len = len;
bifc.ifbic_buf = inbuf = realloc(inbuf, len);
if (inbuf == NULL)
ninbuf = realloc(inbuf, len);
if (ninbuf == NULL)
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)
err(1, "unable to get interface list");
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 ifbareq *ifba;
char *inbuf = NULL;
char *inbuf = NULL, *ninbuf;
int i, len = 8192;
struct ether_addr ea;
for (;;) {
ifbac.ifbac_len = len;
ifbac.ifbac_buf = inbuf = realloc(inbuf, len);
if (inbuf == NULL)
ninbuf = realloc(inbuf, len);
if (ninbuf == NULL)
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)
err(1, "unable to get address cache");
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.
@ -41,7 +41,7 @@
__COPYRIGHT(
"@(#) Copyright (c) 1996, 1997\
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
#include <sys/param.h>
@ -330,7 +330,7 @@ do_all(action)
int action;
{
FILE *f;
char *line, *cp, *vp, **argv;
char *line, *cp, *vp, **argv, **nargv;
int argc, rval;
size_t len;
@ -357,11 +357,13 @@ do_all(action)
if (vp == NULL)
continue;
if ((argv = realloc(argv,
sizeof(char *) * ++argc)) == NULL) {
if ((nargv = realloc(argv,
sizeof(char *) * (argc + 1))) == NULL) {
warnx("no memory to configure ccds");
return (1);
}
argv = nargv;
argc++;
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
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#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 */
#include <sys/types.h>
@ -872,6 +872,7 @@ get_extended_ptn(void)
mbr_partition_t *mp;
mbr_sector_t *boot;
daddr_t offset;
mbr_sector_t *nptn;
/* find first (there should only be one) extended partition */
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.ptn_id = mp - mboot.mbr_parts;
for (offset = 0;; offset = le32toh(boot->mbr_parts[1].mbrp_start)) {
ext.ptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn);
if (ext.ptn == NULL)
nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn);
if (nptn == NULL)
err(1, "Malloc failed");
ext.ptn = nptn;
boot = ext.ptn + ext.num_ptn;
if (read_s0(offset + ext.base, boot) == -1)
break;
@ -1472,8 +1474,12 @@ add_ext_ptn(daddr_t start, daddr_t size)
{
int part;
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++)
if (ext_offset(part) > start)
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
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
#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 /* not lint */
@ -483,7 +483,7 @@ cacheino(dp, inumber)
ino_t inumber;
{
struct inoinfo *inp;
struct inoinfo **inpp;
struct inoinfo **inpp, **ninpsort;
unsigned int blks;
int i;
int64_t size;
@ -515,11 +515,12 @@ cacheino(dp, inumber)
for (i = 0; i < NIADDR; i++)
inp->i_blks[NDADDR + i] = DIP(dp, ib[i]);
if (inplast == listmax) {
listmax += 100;
inpsort = (struct inoinfo **)realloc((char *)inpsort,
(unsigned)listmax * sizeof(struct inoinfo *));
ninpsort = (struct inoinfo **)realloc((char *)inpsort,
(unsigned)(listmax + 100) * sizeof(struct inoinfo *));
if (inpsort == NULL)
errx(EEXIT, "cannot increase directory list");
inpsort = ninpsort;
listmax += 100;
}
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
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
#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 /* not lint */
@ -70,8 +70,9 @@ pass5(void)
struct inodesc idesc[4];
char buf[MAXBSIZE];
struct cg *newcg = (struct cg *)buf;
struct cg *cg = cgrp;
struct cg *cg = cgrp, *ncg;
struct inostat *info;
u_int32_t ncgsize;
inoinfo(WINO)->ino_state = USTATE;
memset(newcg, 0, (size_t)fs->fs_cgsize);
@ -107,13 +108,13 @@ pass5(void)
if (preen)
pwarn("%sING CLUSTER MAPS\n",
doit);
fs->fs_cgsize =
fragroundup(fs, CGSIZE(fs));
cg = cgrp =
realloc(cgrp, fs->fs_cgsize);
if (cg == NULL)
ncgsize = fragroundup(fs, CGSIZE(fs));
ncg = realloc(cgrp, ncgsize);
if (ncg == NULL)
errx(EEXIT,
"cannot reallocate cg space");
cg = cgrp = ncg;
fs->fs_cgsize = ncgsize;
doinglevel1 = 1;
sbdirty();
}