Closed Kadiryanik closed 2 months ago
realloc(NULL, bytes)
is a C99 guarantee, but currently Mini-XML is still limited to the original ANSI C (C89). But a future version of Mini-XML will move the bar to C99 so I'll hold this for 4.0...
Thank you for the update. I didn't know there was such a difference in c89. In the sources below, it is said that it behaves like malloc when calling with NULL. Could you please check it again, if it is as you say, could you share the link of your source?
4.10.3.4 The realloc function void realloc(void ptr, size_t size); ... If ptr is a null pointer, the realloc function behaves like the malloc function for the specified size.
7.10.3.4 The realloc function ... If ptr is a null pointer, the realloc function behaves like the malloc function for the specified size.
Older Unix platforms do not support passing NULL to realloc yet claim C89 conformance. The easiest to verify are the last Sun Solaris and SunOS releases but AIX, HP-UX, IRIX, and Tru64 all had the same problem.
Like I said, I’m ending support for those old platforms with the next major release of Mini-XML…
I got your concern now, thanks.
[master c07a57e] Use realloc for everything (Issue #300)
I made a small change besides the memory controls.
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.