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/e98233036eca
branches:  trunk
changeset: 552117:e98233036eca
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Sep 19 08:29:58 2003 +0000

description:
realloc pedant

diffstat:

 sbin/fsck_lfs/inode.c |  13 +++++++------
 sbin/mount/mount.c    |  22 ++++++++++++----------
 2 files changed, 19 insertions(+), 16 deletions(-)

diffs (96 lines):

diff -r 015dc5318e04 -r e98233036eca sbin/fsck_lfs/inode.c
--- a/sbin/fsck_lfs/inode.c     Fri Sep 19 08:24:07 2003 +0000
+++ b/sbin/fsck_lfs/inode.c     Fri Sep 19 08:29:58 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.20 2003/08/07 10:04:23 agc Exp $        */
+/* $NetBSD: inode.c,v 1.21 2003/09/19 08:31:58 itojun Exp $     */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -347,7 +347,7 @@
 cacheino(struct ufs1_dinode * dp, ino_t inumber)
 {
        struct inoinfo *inp;
-       struct inoinfo **inpp;
+       struct inoinfo **inpp, **ninpsort;
        unsigned int blks;
 
        blks = howmany(dp->di_size, fs->lfs_bsize);
@@ -372,11 +372,12 @@
        inp->i_numblks = blks * sizeof(ufs_daddr_t);
        memcpy(&inp->i_blks[0], &dp->di_db[0], (size_t) inp->i_numblks);
        if (inplast == listmax) {
+               ninpsort = (struct inoinfo **) realloc((char *) inpsort,
+                   (unsigned) (listmax + 100) * sizeof(struct inoinfo *));
+               if (ninpsort == NULL)
+                       err(8, "cannot increase directory list\n");
+               inpsort = ninpsort;
                listmax += 100;
-               inpsort = (struct inoinfo **) realloc((char *) inpsort,
-                   (unsigned) listmax * sizeof(struct inoinfo *));
-               if (inpsort == NULL)
-                       err(8, "cannot increase directory list\n");
        }
        inpsort[inplast++] = inp;
 }
diff -r 015dc5318e04 -r e98233036eca sbin/mount/mount.c
--- a/sbin/mount/mount.c        Fri Sep 19 08:24:07 2003 +0000
+++ b/sbin/mount/mount.c        Fri Sep 19 08:29:58 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount.c,v 1.66 2003/08/07 10:04:26 agc Exp $   */
+/*     $NetBSD: mount.c,v 1.67 2003/09/19 08:29:58 itojun Exp $        */
 
 /*
  * Copyright (c) 1980, 1989, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)mount.c    8.25 (Berkeley) 5/8/95";
 #else
-__RCSID("$NetBSD: mount.c,v 1.66 2003/08/07 10:04:26 agc Exp $");
+__RCSID("$NetBSD: mount.c,v 1.67 2003/09/19 08:29:58 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -575,15 +575,14 @@
        char **sp;
        const char *o;
 {
-       char *s;
-       size_t i, j;
+       char *s, *n;
 
        s = *sp;
        if (s) {
-               i = strlen(s);
-               j = i + 1 + strlen(o) + 1;
-               s = realloc(s, j);
-               (void)snprintf(s + i, j, ",%s", o);
+               if (asprintf(&n, "%s,%s", s, o) < 0)
+                       err(1, "asprintf");
+               free(s);
+               s = n;
        } else
                s = strdup(o);
        *sp = s;
@@ -597,7 +596,7 @@
 {
        char *p, *s;
        int argc, maxargc;
-       const char **argv;
+       const char **argv, **nargv;
 
        argc = *argcp;
        argv = *argvp;
@@ -606,8 +605,11 @@
        for (s = options; (p = strsep(&s, ",")) != NULL;) {
                /* Always leave space for one more argument and the NULL. */
                if (argc >= maxargc - 4) {
+                       nargv = realloc(argv, (maxargc << 1) * sizeof(char *));
+                       if (!nargv)
+                               err(1, "realloc");
+                       argv = nargv;
                        maxargc <<= 1;
-                       argv = realloc(argv, maxargc * sizeof(char *));
                }
                if (*p != '\0') {
                        if (*p == '-') {



Home | Main Index | Thread Index | Old Index