Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdlib be more conservative about allocing.



details:   https://anonhg.NetBSD.org/src/rev/8bb665944484
branches:  trunk
changeset: 757835:8bb665944484
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Sep 25 19:31:51 2010 +0000

description:
be more conservative about allocing.

diffstat:

 lib/libc/stdlib/getenv.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (39 lines):

diff -r 1e1ed8494c67 -r 8bb665944484 lib/libc/stdlib/getenv.c
--- a/lib/libc/stdlib/getenv.c  Sat Sep 25 19:10:37 2010 +0000
+++ b/lib/libc/stdlib/getenv.c  Sat Sep 25 19:31:51 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getenv.c,v 1.21 2010/09/25 18:11:40 tron Exp $ */
+/*     $NetBSD: getenv.c,v 1.22 2010/09/25 19:31:51 christos Exp $     */
 
 /*
  * Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getenv.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getenv.c,v 1.21 2010/09/25 18:11:40 tron Exp $");
+__RCSID("$NetBSD: getenv.c,v 1.22 2010/09/25 19:31:51 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -112,16 +112,16 @@
                        offset++;
        }
 
-       if ((size_t)offset < environ_malloced_len)
+       nl = offset + 2;        /* one for potentially new entry one for NULL */
+       if (nl < environ_malloced_len)
                return 0;
 
-       nl = offset + 2;
-       p = realloc(__environ_malloced, nl * sizeof(char *));
+       p = realloc(__environ_malloced, nl * sizeof(*p));
        if (p == NULL)
                return -1;
 
        (void)memset(&p[environ_malloced_len], 0,
-           (nl - environ_malloced_len) * sizeof(char *));
+           (nl - environ_malloced_len) * sizeof(*p));
        environ_malloced_len = nl;
        __environ_malloced = p;
 



Home | Main Index | Thread Index | Old Index