Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen - Don't update the size of allocated storage un...



details:   https://anonhg.NetBSD.org/src/rev/372feec50f55
branches:  trunk
changeset: 481285:372feec50f55
user:      enami <enami%NetBSD.org@localhost>
date:      Tue Jan 25 16:24:40 2000 +0000

description:
- Don't update the size of allocated storage until realloc successes.
- KNF left over.

diffstat:

 lib/libc/gen/stringlist.c |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (41 lines):

diff -r b737a9529679 -r 372feec50f55 lib/libc/gen/stringlist.c
--- a/lib/libc/gen/stringlist.c Tue Jan 25 16:24:32 2000 +0000
+++ b/lib/libc/gen/stringlist.c Tue Jan 25 16:24:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stringlist.c,v 1.9 2000/01/22 22:19:12 mycroft Exp $   */
+/*     $NetBSD: stringlist.c,v 1.10 2000/01/25 16:24:40 enami Exp $    */
 
 /*-
  * Copyright (c) 1994, 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: stringlist.c,v 1.9 2000/01/22 22:19:12 mycroft Exp $");
+__RCSID("$NetBSD: stringlist.c,v 1.10 2000/01/25 16:24:40 enami Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -96,10 +96,11 @@
        if (sl->sl_cur == sl->sl_max - 1) {
                char    **new;
 
-               sl->sl_max += _SL_CHUNKSIZE;
-               new = (char **)realloc(sl->sl_str, sl->sl_max * sizeof(char *));
+               new = (char **)realloc(sl->sl_str,
+                   (sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));
                if (new == NULL)
                        return (-1);
+               sl->sl_max += _SL_CHUNKSIZE;
                sl->sl_str = new;
        }
        sl->sl_str[sl->sl_cur++] = name;
@@ -146,7 +147,7 @@
                         * XXX check sl->sl_str[i] != NULL?
                         */
                if (strcmp(sl->sl_str[i], name) == 0)
-                       return sl->sl_str[i];
+                       return (sl->sl_str[i]);
 
        return (NULL);
 }



Home | Main Index | Thread Index | Old Index