Lurker News

Comments (218) 56 threads

Show all comments

Showing thread 41 of 56

badsectoracula2 replies#
I get the first one but what is the issue with the second one? It looks like a fairly standard dynamic array with separate size and capacity.
jacquesm1 reply#
Missing null pointer check on return, leaks memory because it overwrites the original pointer.
badsectoracula1 reply#
I didn't notice that, but TBH is this a realistic concern? Is there an actual platform nowadays where realloc (and malloc, for that matter) ever fails, at least outside (small) embedded environments? I've being using realloc for decades and the only time i had to worry about it failing was in DOS.

Nowadays it feels like worrying about realloc failing is similar to worrying about fclose failing.

17186274401 reply#
It is still mandated by the standard, so absence of checking can lead the compiler to conclude UB and optimize stuff away.

Also it is commonly made to return NULL for testing.

Continue this thread — 1 reply

cyberax#
No null pointer check, and the fact that you have to manually rewrite it every time.