test-strndup fails on AIX (cfarm119) with ibm-clang because
strndup(NULL, 0) == NULL isn't true. I had configured with CC=ibm-clang
CFLAGS=-O2. With -O0 it works.
The problem is that the strndup(NULL, 0) check in strndup.m4 is
optimized away, perhaps because the result isn't used. Testing on
Godbolt shows that x86-64 Clang >= 3.6 and GCC >= 15.1 do the same.
It's not due to the prototype in <string.h>, the NULL, or the 0,
because the following is optimized away too:
#include <stddef.h>
char *strndup(const char *s, size_t n);
int main(void)
{
char buf[] = "abcd";
int result = 0;
if (strndup (NULL, 0) == NULL)
result |= 2;
if (strndup (buf, 0) == NULL)
result |= 4;
if (strndup (buf, 1) == NULL)
result |= 8;
if (strndup (buf, 3) == NULL)
result |= 16;
return result;
}
This seems to work:
char *volatile ptr;
if ((ptr = strndup (NULL, 0)) == NULL)
result |= 2;
--
Lasse Collin