Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 21 Oct 2022 18:09:42 -0400
From: James Y Knight <>
Cc: Rich Felker <>, Ismael Luceno <>
Subject: Re: [RFC PATCH] implement strndupa

>  #define        strdupa(x)      strcpy(alloca(strlen(x)+1),x)
> +#define        strndupa(x, n)  strlcpy(alloca(strnlen((x), (n)), (x), (n))

This causes the parameters to be evaluated multiple times -- and that is
also a problem with the existing strdupa. Unfortunately it's impossible to
implement these macros without multiple-evaluation, unless you use the GCC
statement-expression language extension (as glibc does).

IMO, musl should either use that extension, despite the general policy of
avoiding such non-standard language extensions, or simply not implement
these functions at all. Implementing them, but having them incorrectly
multiply-evaluate the parameters seems like the worst of the options...

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.