[PATCH] [Review request][analyzer] Duplicate '0 size allocation' check from unix.API in unix.Malloc.
anton.yartsev at gmail.com
Fri Nov 7 16:11:58 PST 2014
This duplication was motivated by the following:
- FIXME from unix.API stating "Eventually these should be rolled into the MallocChecker, but right now they're more basic and valuable for widespread use."
- an idea to extend the check to handle zero size allocation by 'new' and 'new' in the sequel.
- create the base for implementation of undefbehavior.ZeroAllocDereference checker.
The patch is a scratch, may it make sense to make '0 size allocation' the separate checker to at least preserve handling of zero-size realloc unchanged.
I suggest the following logic for handling zero-size realloc:
1) if the returned value of realloc(p, 0) is not assigned then silently treat it as simple 'free' (the old behavior of unix.Malloc)
2) if the returned value is assigned then fire '0 size allocation' warning as the usage of the returned pointer is not safe.
Specification C11 n1570, 188.8.131.52 says: "If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object."
Usage of the returned pointer is planned to be a matter of other checkers (undefbehavior.ZeroAllocDereference + maybe another checker that checks for usage of returned pointer in comparisons)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 27884 bytes
Desc: not available
More information about the cfe-commits