Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin realloc pedant



details:   https://anonhg.NetBSD.org/src/rev/296369634fcc
branches:  trunk
changeset: 552119:296369634fcc
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Sep 19 08:35:15 2003 +0000

description:
realloc pedant

diffstat:

 sbin/brconfig/brconfig.c   |  22 ++++++++++++----------
 sbin/ccdconfig/ccdconfig.c |  12 +++++++-----
 sbin/fdisk/fdisk.c         |  16 +++++++++++-----
 sbin/fsck_ffs/inode.c      |  13 +++++++------
 sbin/fsck_ffs/pass5.c      |  17 +++++++++--------
 5 files changed, 46 insertions(+), 34 deletions(-)

diffs (246 lines):

diff -r bf86797e2edc -r 296369634fcc sbin/brconfig/brconfig.c
--- a/sbin/brconfig/brconfig.c  Fri Sep 19 08:32:26 2003 +0000
+++ b/sbin/brconfig/brconfig.c  Fri Sep 19 08:35:15 2003 +0000
@@ -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 @@
        };
        struct ifbifconf bifc;
        struct ifbreq *req;
-       char *inbuf = NULL;
+       char *inbuf = NULL, *ninbuf;
        int i, len = 8192;
 
        for (;;) {
+               ninbuf = realloc(inbuf, len);
+               if (ninbuf == NULL)
+                       err(1, "unable to allocate interface buffer");
                bifc.ifbic_len = len;
-               bifc.ifbic_buf = inbuf = realloc(inbuf, len);
-               if (inbuf == NULL)
-                       err(1, "unable to allocate interface buffer");
+               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 @@
 {
        struct ifbaconf ifbac;
        struct ifbareq *ifba;
-       char *inbuf = NULL;
+       char *inbuf = NULL, *ninbuf;
        int i, len = 8192;
        struct ether_addr ea;
 
        for (;;) {
+               ninbuf = realloc(inbuf, len);
+               if (ninbuf == NULL)
+                       err(1, "unable to allocate address buffer");
                ifbac.ifbac_len = len;
-               ifbac.ifbac_buf = inbuf = realloc(inbuf, len);
-               if (inbuf == NULL)
-                       err(1, "unable to allocate address buffer");
+               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)
diff -r bf86797e2edc -r 296369634fcc sbin/ccdconfig/ccdconfig.c
--- a/sbin/ccdconfig/ccdconfig.c        Fri Sep 19 08:32:26 2003 +0000
+++ b/sbin/ccdconfig/ccdconfig.c        Fri Sep 19 08:35:15 2003 +0000
@@ -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 @@
        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 @@
                        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;
 
                        /*
diff -r bf86797e2edc -r 296369634fcc sbin/fdisk/fdisk.c
--- a/sbin/fdisk/fdisk.c        Fri Sep 19 08:32:26 2003 +0000
+++ b/sbin/fdisk/fdisk.c        Fri Sep 19 08:35:15 2003 +0000
@@ -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 @@
        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 @@
        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 @@
 {
        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;
diff -r bf86797e2edc -r 296369634fcc sbin/fsck_ffs/inode.c
--- a/sbin/fsck_ffs/inode.c     Fri Sep 19 08:32:26 2003 +0000
+++ b/sbin/fsck_ffs/inode.c     Fri Sep 19 08:35:15 2003 +0000
@@ -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 @@
        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 @@
                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;
 }
diff -r bf86797e2edc -r 296369634fcc sbin/fsck_ffs/pass5.c
--- a/sbin/fsck_ffs/pass5.c     Fri Sep 19 08:32:26 2003 +0000
+++ b/sbin/fsck_ffs/pass5.c     Fri Sep 19 08:35:15 2003 +0000
@@ -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 @@
        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 @@
                                        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();
                                }



Home | Main Index | Thread Index | Old Index