3 ms·
Regarding calloc, the issue is this: - Since C++14, SIZE_MAX is the maximum size of any valid object; any object larger is ill-formed. - calloc(SIZE_MAX, SIZE
by pubby 8y ago
Regarding calloc, the issue is this:
- Since C++14, SIZE_MAX is the maximum size of any valid object; any object larger is ill-formed.
- calloc(SIZE_MAX, SIZE_MAX) is an attempt at creating an invalid object of size SIZE_MAX^2.
- Thus, calloc(SIZE_MAX, SIZE_MAX) should always return null. Shouldn't it?
Compilers often remove malloc calls even if the allocated object is modified and freed. But they shouldn't change the program's visible semantics.
- vardump 8y ago> Compilers often remove malloc calls even if the allocated object is modified and freed. But they shouldn't change the program's visible semantics. What visible side effects there are for an allocation with an unused return value pointer (cast to a boolean)? There's no way to reference said memory, so there's no way it can affect execution of the abstract program. If the allocation succeeded, there's no way to free the memory in any case. So even ignoring possible concurrent allocations elsewhere, it's useless for checking whether future malloc can succeed. Unless, of course, I missed something obvious.