Invalid strdupa implementation in /usr/include/string.h
While compiling bazel from scratch I encountered problem with implementation of strdupa function in string.h file. The problem from compiling one of the bazel’s files is as follows:
In file included from src/main/tools/linux-sandbox-pid1.cc:47:0:
src/main/tools/linux-sandbox-pid1.cc: In function 'int CreateTarget(const char*, bool)':
src/main/tools/linux-sandbox-pid1.cc:210:28: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
if (CreateTarget(dirname(strdupa(path)), true) < 0) {
^
In file included from src/main/tools/linux-sandbox-pid1.cc:47:0:
/usr/include/string.h:31:7: note: initializing argument 1 of 'char* strcpy(char*, const char*)'
char *strcpy (char *__restrict, const char *__restrict);
^~~~~~
src/main/tools/linux-sandbox-pid1.cc:211:43: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
DIE("CreateTarget(%s, true)", dirname(strdupa(path)));
Which means that there is a problem with strdupa function. When I checked the implementation of strdupa in string.h I saw following code:
#define strdupa(x) strcpy(alloca(strlen(x)+1),x)
Which probably is the source of the problem since alloca returns void* but strcpy() requires char*.
From /usr/include/alloca.h:
void *alloca(size_t);
(from redmine: issue id 6893, created on 2017-02-19)