Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdlib Double the array only when really necessary....



details:   https://anonhg.NetBSD.org/src/rev/4ce333d5d6e0
branches:  trunk
changeset: 758305:4ce333d5d6e0
user:      enami <enami%NetBSD.org@localhost>
date:      Mon Nov 01 02:41:27 2010 +0000

description:
Double the array only when really necessary.  Otherwise memory will be
exhausted if user modifies the variable envrion itself repeatedly..

diffstat:

 lib/libc/stdlib/getenv.c |  7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diffs (28 lines):

diff -r 8dd308d96ec0 -r 4ce333d5d6e0 lib/libc/stdlib/getenv.c
--- a/lib/libc/stdlib/getenv.c  Mon Nov 01 02:35:24 2010 +0000
+++ b/lib/libc/stdlib/getenv.c  Mon Nov 01 02:41:27 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getenv.c,v 1.26 2010/10/24 17:53:27 tron Exp $ */
+/*     $NetBSD: getenv.c,v 1.27 2010/11/01 02:41:27 enami 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.26 2010/10/24 17:53:27 tron Exp $");
+__RCSID("$NetBSD: getenv.c,v 1.27 2010/11/01 02:41:27 enami Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -120,8 +120,7 @@
                return 0;
 
        /* Make sure we at least double the size of the arrays. */
-       new_len = (environ_malloced_len >= 16) ?
-           (environ_malloced_len << 1) : 16;
+       new_len = environ_malloced_len >= 16 ? environ_malloced_len : 16;
        while (new_len < required_len)
                new_len = new_len << 1;
 



Home | Main Index | Thread Index | Old Index