https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79839
Bug ID: 79839
Summary: malloc(0) returns 0 on AIX even with
_LINUX_SOURCE_COMPAT
Product: gcc
Version: 4.8.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: jaideepbajwa at hotmail dot com
Target Milestone: ---
Target: aix
malloc(0) returning 0 is expected behaviour on AIX but compiling with
-D_LINUX_SOURCE_COMPAT, malloc(0) should return a valid pointer. As per:
https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.basetrf1/malloc.html
It doesn't work for c++ program which includes <cstdlib>. In the header it
states:
// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
...
#undef malloc
The above seems to be causing the issue and resetting the behaviour of
-D_LINUX_SOURCE_COMPAT.
Code to reproduce:
>cat malloc.cpp
#include <stdio.h>
//#include <stdlib.h> //<-- Works this stdlib
#include <cstdlib>
int main() {
printf("%p \n", malloc(0));
return 0;
}
>g++ malloc.cpp -D_LINUX_SOURCE_COMPAT
>./a.out
0