mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Problem with strdupa in C++ code
@ 2022-04-12  1:06 Wolf
  2022-04-12 16:15 ` Markus Wichmann
  0 siblings, 1 reply; 3+ messages in thread
From: Wolf @ 2022-04-12  1:06 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1585 bytes --]

Hello,

I'm trying to compile C++ project in Alpine (so with musl) and I'm
hitting following error:

    In file included from /usr/include/fortify/string.h:22,
                     from src/main/tools/linux-sandbox-pid1.cc:34:
    src/main/tools/linux-sandbox-pid1.cc: In function 'int CreateTarget(const char*, bool)':
    src/main/tools/linux-sandbox-pid1.cc:149:28: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
      149 |   if (CreateTarget(dirname(strdupa(path)), true) < 0) {
          |                            ^
          |                            |
          |                            void*
    In file included from /usr/include/fortify/string.h:22,
                     from src/main/tools/linux-sandbox-pid1.cc:34:
    /usr/include/string.h:31:15: note:   initializing argument 1 of 'char* strcpy(char*, const char*)'
       31 | char *strcpy (char *__restrict, const char *__restrict);
          |               ^~~~~~~~~~~~~~~~
    
If my reading for musl's code is correct, this is actually a bug in the
header file, since the declarations are:

    void *alloca(size_t);
    #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)

As far as I know, there is no automatic conversion from void* to char*
in C++. Should this be fixed by turning the define into

    #define	strdupa(x)	strcpy((char*)alloca(strlen(x)+1),x)

? I think that should be both valid C and C++.

Best regards,
Tomas Volf

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-12 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  1:06 [musl] Problem with strdupa in C++ code Wolf
2022-04-12 16:15 ` Markus Wichmann
2022-04-12 16:24   ` Joakim Sindholt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).