michaelrsweet / mxml

Tiny XML library.
https://www.msweet.org/mxml
Apache License 2.0
426 stars 157 forks source link

Memory controls have been added #299

Closed Kadiryanik closed 1 year ago

Kadiryanik commented 1 year ago

I made a small change besides the memory controls.

if (!ind->alloc_nodes)
  temp = malloc(64 * sizeof(mxml_node_t *));
else
  temp = realloc(ind->nodes, (ind->alloc_nodes + 64) * sizeof(mxml_node_t *));

Since the ind is allocated with the calloc, ind->nodes contains NULL and _ind->allocnodes contains 0. realloc works as malloc if the first parameter is NULL. Your size is also same for both. (_ind->allocnodes=0 + 64 = 64)

So we can rid of the if statement and we can use realloc for both case.