Michael Stefaniuc mstefani@mykolab.com writes:
The current usage is clean only because we are not checking for allocation failure, but that's broken. If we add proper handling, then the NULL checks will be needed anyway.
I assumed you want less HeapAlloc failure handling and not more! Especially as in the strdup cases the current "return NULL" seems to be good enough in practice. I don't remember to have ever seen a patch that adds extra error handling for that case.
You could argue that strdup() should be treated as a nofail function, but then you should remove the second null check and let it crash on the memcpy, or use HEAP_GENERATE_EXCEPTIONS. I'd prefer to have an explicit xstrdup() function for this though, and have the regular strdup() require error handling.