mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Wolf <wolf@wolfsden.cz>
To: musl@lists.openwall.com
Subject: [musl] Problem with strdupa in C++ code
Date: Tue, 12 Apr 2022 03:06:08 +0200	[thread overview]
Message-ID: <YlTQgBwQEgukb3N3@ws> (raw)

[-- 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 --]

             reply	other threads:[~2022-04-12  1:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12  1:06 Wolf [this message]
2022-04-12 16:15 ` Markus Wichmann
2022-04-12 16:24   ` Joakim Sindholt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YlTQgBwQEgukb3N3@ws \
    --to=wolf@wolfsden.cz \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).