From: Rich Felker <email@example.com>
To: NRK <firstname.lastname@example.org>
Cc: email@example.com, Tamir Duberstein <firstname.lastname@example.org>
Subject: Re: [musl] undefined behavior in fread.c
Date: Fri, 24 Feb 2023 09:07:41 -0500 [thread overview]
Message-ID: <20230224140739.GF4163@brightrain.aerifal.cx> (raw)
On Fri, Feb 24, 2023 at 07:55:11PM +0600, NRK wrote:
> On Fri, Feb 24, 2023 at 08:34:14AM -0500, Rich Felker wrote:
> > Is there any indication that passing NULL as the first argument to
> > fread is not itself undefined?
> C99 says the following:
> | If size or nmemb is zero, fread returns zero and the contents of the
> | array and the state of the stream remain unchanged.
> It doesn't explicitly mention weather stream can be NULL or not in case
> of 0 size/nmemb - but regardless, is there any actual reason for not
> returning early?
> The following should be OK as far as I see:
> - if (!size) nmemb = 0;
> + if (!size || !nmemb) return 0;
> or `if (!len) return 0;` could also work if multiplication overflow is
> not a concern.
stdio functions are required (by POSIX) to behave as if they take a
mutex on the FILE. If fread with a length of zero makes forward
progress when another thread holds the lock, this is non-conforming.
next prev parent reply other threads:[~2023-02-24 14:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 12:52 Tamir Duberstein
2023-02-24 13:34 ` Rich Felker
2023-02-24 13:53 ` Jₑₙₛ Gustedt
2023-02-24 13:55 ` NRK
2023-02-24 14:07 ` Rich Felker [this message]
2023-02-24 14:17 ` NRK
2023-02-24 14:42 ` Tamir Duberstein
2023-02-24 15:13 ` NRK
2023-02-24 16:12 ` Tamir Duberstein
2023-02-24 16:40 ` Jₑₙₛ Gustedt
2023-02-24 16:42 ` Tamir Duberstein
2023-02-24 17:00 ` Jₑₙₛ Gustedt
2023-02-24 17:07 ` enh
2023-02-24 17:32 ` Tamir Duberstein
2023-02-24 16:42 ` enh
2023-02-24 20:07 ` Rich Felker
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:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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
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).