From 9818fa6bc31bcfee9ad20da0e53fb0ce23856e07 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 16 Nov 2005 15:12:19 +0000 Subject: [PATCH] add_variable() just threw away the freshly copied environment (makes me wonder why things worked nevertheless with the old gcc). We now also use realloc() instead of malloc()+memcpy(), and check add_variable()'s return code. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14957 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/stdlib/env.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/system/libroot/posix/stdlib/env.c b/src/system/libroot/posix/stdlib/env.c index 4a7d6a7a68..8af820fb7e 100644 --- a/src/system/libroot/posix/stdlib/env.c +++ b/src/system/libroot/posix/stdlib/env.c @@ -44,14 +44,15 @@ static int32 add_variable(void) { int32 count = count_variables() + 1; - char **newEnv = malloc((count + 1) * sizeof(char *)); + char **newEnv = realloc(environ, (count + 1) * sizeof(char *)); if (newEnv == NULL) return B_NO_MEMORY; - memcpy(newEnv, environ, count * sizeof(char *)); newEnv[count] = NULL; // null terminate the array + environ = newEnv; + return count - 1; } @@ -118,7 +119,10 @@ update_variable(const char *name, int32 length, const char *value, bool overwrit } else if (env == NULL) { // add variable index = add_variable(); - update = true; + if (index >= 0) + update = true; + else + status = index; } if (update) {