mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Alejandro Colomar <alx@kernel.org>
Cc: Leah Neukirchen <leah@vuxu.org>, musl@lists.openwall.com
Subject: Re: [musl] gcvt(3) should be MT-Safe, AS-Safe, AC-Safe
Date: Wed, 1 May 2024 13:21:39 -0400	[thread overview]
Message-ID: <20240501172138.GC10433@brightrain.aerifal.cx> (raw)
In-Reply-To: <ZjJh4cvtKq7xCc2z@debian>

On Wed, May 01, 2024 at 05:38:03PM +0200, Alejandro Colomar wrote:
> Hi Leah,
> 
> On Wed, May 01, 2024 at 05:19:25PM +0200, Leah Neukirchen wrote:
> > Alejandro Colomar <alx@kernel.org> writes:
> > > glibc's gcvt(1) is documented to be MT-Safe | AS-Safe | AC-Safe.
> > > <https://sourceware.org/glibc/manual/latest/html_mono/libc.html#index-gcvt>
> > > It's an interesting function to be called from a signal handler, where
> > > snprintf(3) is not available.
> > >
> > > But musl implements it as a call to sprintf(3); that doesn't seem safe.
> > 
> > POSIX 2001 says:
> > https://pubs.opengroup.org/onlinepubs/009695399/functions/gcvt.html
> 
> It seems POSIX doesn't require it to be safe.
> 
> However, it is _useful_ to make it safe as an extension to POSIX.
> 
> Solaris 11 documents it as MT-Level Safel; they don't list it as
> "Async-Signal-Safe", though.  :/
> 
> > > These functions need not be reentrant. A function that is not
> > > required to be reentrant is not required to be thread-safe.
> > 
> > POSIX 2008 removed the whole function.
> 
> Yup.  But that doesn't mean it's a useless function.
> 
> > I recommend not putting application logic into signal handlers.
> 
> I was looking at this:
> <https://gitlab.com/muttmua/mutt/-/blob/master/signal.c?ref_type=heads#L95>
> which implements something like gcvt(3) (but moch more basic) to report
> an error, and was wondering if anything from libc would work.  gcvt(3)
> is not portable, so it's not usable there, but it was interesting,
> nevertheless.
> 
> Have a lovely day!

It doesn't matter either way because musl's s[n]printf is AS-safe.

Rich

  reply	other threads:[~2024-05-01 17:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 15:09 Alejandro Colomar
2024-05-01 15:19 ` Leah Neukirchen
2024-05-01 15:38   ` Alejandro Colomar
2024-05-01 17:21     ` Rich Felker [this message]
2024-05-01 19:55       ` Alejandro Colomar
2024-05-01 23:04         ` Rich Felker
2024-05-01 23:45           ` Alejandro Colomar
2024-05-01 23:57             ` Thorsten Glaser
2024-05-02  0:01             ` Alejandro Colomar
2024-05-02 20:34               ` Joseph Myers

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=20240501172138.GC10433@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=alx@kernel.org \
    --cc=leah@vuxu.org \
    --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).