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
This commit is contained in:
Ingo Weinhold
2005-11-16 15:12:19 +00:00
parent aabcf63973
commit 9818fa6bc3
+7 -3
View File
@@ -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) {