When encountering a possible malloc(0), the clang analyzer reports a "Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)" bug. This text is wrong, since malloc(0) is not *undefined*; rather, it is *implementation-defined*. A global s/Undefined allocation/Implementation-defined allocation/ in the clang-analyzer source code should fix this.
Not only is malloc(0) not undefined behaviour, the two alternatives offered for implementation dependent behaviour (NULL or some other value that can safely be passed to free) are enough to fully define the behaviour of malloc(0). The only caveats are: 1. It's implementation defined whether the caller can test for NULL when checking for failure. 2. It would seem the meaning of realloc(malloc(0), size) might be implementation defined. In brief, although calling malloc(0) might be a precondition for one of these two errors, in itself it is *not* a defect or a sign of a defect. This this warning is itself in error.