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:
parent
bc2a35cd4e
commit
2887dd2117
10
parser.c
10
parser.c
@ -67,6 +67,7 @@ HE_face *parse_obj(char const * const filename)
|
|||||||
|
|
||||||
if (!strcmp(str_tmp_ptr, "v")) { /* parse vertices */
|
if (!strcmp(str_tmp_ptr, "v")) { /* parse vertices */
|
||||||
char *myfloat = NULL;
|
char *myfloat = NULL;
|
||||||
|
HE_vert *tmp_ptr;
|
||||||
|
|
||||||
/* fill x */
|
/* fill x */
|
||||||
myfloat = strtok_r(NULL, " ", &str_ptr_space);
|
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);
|
vertices[vc - 1].z = atof(myfloat);
|
||||||
|
|
||||||
vc++;
|
vc++;
|
||||||
vertices = realloc(vertices,
|
tmp_ptr = realloc(vertices,
|
||||||
vert_size * vc);
|
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 */
|
} else if (!strcmp(str_tmp_ptr, "f")) { /* parse faces */
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user