* [musl] basename with no parameter?
@ 2022-03-07 2:31 wangjianjian (C)
2022-03-07 13:18 ` Rich Felker
0 siblings, 1 reply; 5+ messages in thread
From: wangjianjian (C) @ 2022-03-07 2:31 UTC (permalink / raw)
To: musl
Hi all,
I find that the basename in string.h with _GNU_SOURCE in Musl libc(Line
119):
char *basename();
The man page says that have two different version of basename however
both need one parameter, is this correct?
Regards,
Jian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] basename with no parameter?
2022-03-07 2:31 [musl] basename with no parameter? wangjianjian (C)
@ 2022-03-07 13:18 ` Rich Felker
2022-03-07 16:42 ` James Y Knight
2022-03-26 3:34 ` wangjianjian (C)
0 siblings, 2 replies; 5+ messages in thread
From: Rich Felker @ 2022-03-07 13:18 UTC (permalink / raw)
To: wangjianjian (C); +Cc: musl
On Mon, Mar 07, 2022 at 10:31:41AM +0800, wangjianjian (C) wrote:
> Hi all,
>
> I find that the basename in string.h with _GNU_SOURCE in Musl
> libc(Line 119):
>
> char *basename();
This is not a declaration with no parameter. It's a declaration
without any prototype.
> The man page says that have two different version of basename
> however both need one parameter, is this correct?
No, that's documenting glibc. There is only one version of basename in
musl and it's the standard one.
The reason for the non-prototype declaration is explained in commit
37bb3cce4598c19288628e675eaf1cda6e96958f:
omit declaration of basename wrongly interpreted as prototype in C++
the non-prototype declaration of basename in string.h is an ugly
compromise to avoid breaking 2 types of broken software:
1. programs which assume basename is declared in string.h and thus
would suffer from dangerous pointer-truncation if an implicit
declaration were used.
2. programs which include string.h with _GNU_SOURCE defined but then
declare their own prototype for basename using the incorrect GNU
signature for the function (which would clash with a correct
prototype).
however, since C++ does not have non-prototype declarations and
interprets them as prototypes for a function with no arguments, we
must omit it when compiling C++ code. thankfully, all known broken
apps that suffer from the above issues are written in C, not C++.
This was from 2012, so it might make sense to do something different
now, like putting the correct prototype there and getting any programs
it still clashes with fixed.
Rich
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] basename with no parameter?
2022-03-07 13:18 ` Rich Felker
@ 2022-03-07 16:42 ` James Y Knight
2022-03-07 18:38 ` Rich Felker
2022-03-26 3:34 ` wangjianjian (C)
1 sibling, 1 reply; 5+ messages in thread
From: James Y Knight @ 2022-03-07 16:42 UTC (permalink / raw)
To: musl; +Cc: wangjianjian (C)
[-- Attachment #1: Type: text/plain, Size: 2409 bytes --]
Note that the C2x standard intends to remove deprecated non-prototype
declarations, along with K&R-style non-prototype definitions. Empty
parens in a declaration will be treated as a zero-arg prototype, just as in
C++. (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm).
Additionally, compilers may start emitting some default-on warnings for use
of these deprecated features even in pre-C2x language modes, although
that'd likely be suppressed for system headers.
It'd probably be a good idea to remove any such hacks which depend on
non-prototype declarations, to get ahead of these changes.
On Mon, Mar 7, 2022 at 8:19 AM Rich Felker <dalias@libc.org> wrote:
> On Mon, Mar 07, 2022 at 10:31:41AM +0800, wangjianjian (C) wrote:
> > Hi all,
> >
> > I find that the basename in string.h with _GNU_SOURCE in Musl
> > libc(Line 119):
> >
> > char *basename();
>
> This is not a declaration with no parameter. It's a declaration
> without any prototype.
>
> > The man page says that have two different version of basename
> > however both need one parameter, is this correct?
>
> No, that's documenting glibc. There is only one version of basename in
> musl and it's the standard one.
>
> The reason for the non-prototype declaration is explained in commit
> 37bb3cce4598c19288628e675eaf1cda6e96958f:
>
> omit declaration of basename wrongly interpreted as prototype in C++
>
> the non-prototype declaration of basename in string.h is an ugly
> compromise to avoid breaking 2 types of broken software:
>
> 1. programs which assume basename is declared in string.h and thus
> would suffer from dangerous pointer-truncation if an implicit
> declaration were used.
>
> 2. programs which include string.h with _GNU_SOURCE defined but then
> declare their own prototype for basename using the incorrect GNU
> signature for the function (which would clash with a correct
> prototype).
>
> however, since C++ does not have non-prototype declarations and
> interprets them as prototypes for a function with no arguments, we
> must omit it when compiling C++ code. thankfully, all known broken
> apps that suffer from the above issues are written in C, not C++.
>
> This was from 2012, so it might make sense to do something different
> now, like putting the correct prototype there and getting any programs
> it still clashes with fixed.
>
> Rich
>
[-- Attachment #2: Type: text/html, Size: 3034 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] basename with no parameter?
2022-03-07 16:42 ` James Y Knight
@ 2022-03-07 18:38 ` Rich Felker
0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2022-03-07 18:38 UTC (permalink / raw)
To: James Y Knight; +Cc: musl, wangjianjian (C)
On Mon, Mar 07, 2022 at 11:42:39AM -0500, James Y Knight wrote:
> Note that the C2x standard intends to remove deprecated non-prototype
> declarations, along with K&R-style non-prototype definitions. Empty
> parens in a declaration will be treated as a zero-arg prototype, just as in
> C++. (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm).
I was vaguely aware of this, and it's somewhat unfortunate because it
removes some power from the language. There are some magical tricks
you can do with non-prototype declarations and _Generic that will no
longer be possible...
> Additionally, compilers may start emitting some default-on warnings for use
> of these deprecated features even in pre-C2x language modes, although
> that'd likely be suppressed for system headers.
>
> It'd probably be a good idea to remove any such hacks which depend on
> non-prototype declarations, to get ahead of these changes.
Seems like a good idea. I wonder whether we should remove the
declaration entirely here or put back the prototype...
Rich
> On Mon, Mar 7, 2022 at 8:19 AM Rich Felker <dalias@libc.org> wrote:
>
> > On Mon, Mar 07, 2022 at 10:31:41AM +0800, wangjianjian (C) wrote:
> > > Hi all,
> > >
> > > I find that the basename in string.h with _GNU_SOURCE in Musl
> > > libc(Line 119):
> > >
> > > char *basename();
> >
> > This is not a declaration with no parameter. It's a declaration
> > without any prototype.
> >
> > > The man page says that have two different version of basename
> > > however both need one parameter, is this correct?
> >
> > No, that's documenting glibc. There is only one version of basename in
> > musl and it's the standard one.
> >
> > The reason for the non-prototype declaration is explained in commit
> > 37bb3cce4598c19288628e675eaf1cda6e96958f:
> >
> > omit declaration of basename wrongly interpreted as prototype in C++
> >
> > the non-prototype declaration of basename in string.h is an ugly
> > compromise to avoid breaking 2 types of broken software:
> >
> > 1. programs which assume basename is declared in string.h and thus
> > would suffer from dangerous pointer-truncation if an implicit
> > declaration were used.
> >
> > 2. programs which include string.h with _GNU_SOURCE defined but then
> > declare their own prototype for basename using the incorrect GNU
> > signature for the function (which would clash with a correct
> > prototype).
> >
> > however, since C++ does not have non-prototype declarations and
> > interprets them as prototypes for a function with no arguments, we
> > must omit it when compiling C++ code. thankfully, all known broken
> > apps that suffer from the above issues are written in C, not C++.
> >
> > This was from 2012, so it might make sense to do something different
> > now, like putting the correct prototype there and getting any programs
> > it still clashes with fixed.
> >
> > Rich
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] basename with no parameter?
2022-03-07 13:18 ` Rich Felker
2022-03-07 16:42 ` James Y Knight
@ 2022-03-26 3:34 ` wangjianjian (C)
1 sibling, 0 replies; 5+ messages in thread
From: wangjianjian (C) @ 2022-03-26 3:34 UTC (permalink / raw)
To: musl
> >>This was from 2012, so it might make sense to do something different
> >> now, like putting the correct prototype there and getting any programs
> >> it still clashes with fixed.
So what's the next step ? Can I cook a patch to fix this ?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-26 3:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 2:31 [musl] basename with no parameter? wangjianjian (C)
2022-03-07 13:18 ` Rich Felker
2022-03-07 16:42 ` James Y Knight
2022-03-07 18:38 ` Rich Felker
2022-03-26 3:34 ` wangjianjian (C)
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).