Fix realloc() usage

We must not do:
  foo = realloc(foo, ...)
if realloc fails, then we have no idea about it, so we
have to use temporary NULL initialized pointers.
This commit is contained in:
hasufell 2014-05-07 21:13:29 +02:00
parent bc2a35cd4e
commit 2887dd2117
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 8 additions and 2 deletions

View File

@ -67,6 +67,7 @@ HE_face *parse_obj(char const * const filename)
if (!strcmp(str_tmp_ptr, "v")) { /* parse vertices */
char *myfloat = NULL;
HE_vert *tmp_ptr;
/* fill x */
myfloat = strtok_r(NULL, " ", &str_ptr_space);
@ -84,9 +85,14 @@ HE_face *parse_obj(char const * const filename)
vertices[vc - 1].z = atof(myfloat);
vc++;
vertices = realloc(vertices,
tmp_ptr = realloc(vertices,
vert_size * vc);
CHECK_PTR_VAL(vertices);
CHECK_PTR_VAL(tmp_ptr);
vertices = tmp_ptr;
/* exceeds 3 dimensions, malformed vertice */
if (strtok_r(NULL, " ", &str_ptr_space))
return NULL;
} else if (!strcmp(str_tmp_ptr, "f")) { /* parse faces */
/* TODO */
}