cpp_scope_pop() now handles platforms where realloc(a, 0) returns NULL

This commit is contained in:
Pierre Pronchery 2008-05-27 01:24:13 +00:00
parent 184130ccf0
commit cb7f99b4c9

View File

@ -411,7 +411,12 @@ static int _cpp_scope_pop(Cpp * cpp)
CppScope * p;
assert(cpp->scopes_cnt > 0);
if((p = realloc(cpp->scopes, sizeof(*p) * (cpp->scopes_cnt - 1)))
if(cpp->scopes_cnt == 1)
{
free(cpp->scopes);
p = NULL;
}
else if((p = realloc(cpp->scopes, sizeof(*p) * (cpp->scopes_cnt - 1)))
== NULL)
return error_set_code(1, "%s", strerror(errno));
cpp->scopes = p;