public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: "Keith Packard" <keithp@keithp.com>
To: Josef Wolf <jw@raven.inka.de>, newlib@sourceware.org
Subject: Re: undefined references since newlib-3.2.0
Date: Sat, 13 Jun 2020 10:20:54 -0700	[thread overview]
Message-ID: <87pna2hog9.fsf@keithp.com> (raw)
In-Reply-To: <20200613082709.GF15174@raven.inka.de>

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

Josef Wolf <jw@raven.inka.de> writes:

> I don't really understand this. The classical way to return error from
> functions returning a pointer is to return NULL. One has to make sure not to
> leak, of course. Which return values would be needed beyond NULL?

The issue is that you need to reflect the allocation error all the way
up to the initial libc entry point, and you need to use a defined error
return value at that point, preferably one which indicates that the
library had an internal allocation failure.

Here are some affected libc functions which don't return a pointer and
which have no error indication of any kind:

        atof
        atoff

These are defined to just return strtod/strtof, so they continue to
inherit whatever those functions do. Which is now:

These have errnos defined, but those do not include ENOMEM:

        strtod
        strtof
        strtold
        wcstod
        wcstold
        strtodg

These now return infinity and set errno to ERANGE on allocation
failure. (not ideal, but the options are limited)

Here are some which do return a pointer, but do not document any errors:

        ecvt
        fcvt
        gcvt
        ecvtbuf
        fcvtbuf
        gcvtbuf

These now can return NULL on allocation failure. They do not set errno.

And here's a list of functions which I feel reasonable applications
should not expect an allocation error from:

        sprintf
        snprintf
        sscanf
        
These return EOF on allocation failure.

I wasn't too concerned with the exact semantics as there are no good
answers when libc uses malloc in these functions, so once I had
eliminated the internal aborts, I moved on to adding the ryu conversion
code to tinystdio to eliminate allocation in that path entirely.

-- 
-keith

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

  reply	other threads:[~2020-06-13 17:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-09  8:00 Wolf, Josef
2020-06-12  8:21 ` Josef Wolf
2020-06-12 22:50   ` Josef Wolf
2020-06-13  0:05     ` Keith Packard
2020-06-13  8:27       ` Josef Wolf
2020-06-13 17:20         ` Keith Packard [this message]
2020-06-14 14:50           ` Josef Wolf
2020-06-14 17:02             ` Keith Packard
2020-06-14 17:40               ` Brian Inglis
2020-06-14 20:13                 ` Keith Packard
2020-06-15  4:53               ` Dimitrios Glynos
2020-06-16  3:43                 ` Keith Packard
2020-06-17 11:36           ` Josef Wolf
2020-06-13 10:31     ` Jeffrey Walton

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=87pna2hog9.fsf@keithp.com \
    --to=keithp@keithp.com \
    --cc=jw@raven.inka.de \
    --cc=newlib@sourceware.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).