mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: <shadow.h> function: fgetspent_r
Date: Thu, 17 Jan 2019 06:31:47 +0100	[thread overview]
Message-ID: <20190117053147.GH29911@voyager> (raw)
In-Reply-To: <20190116234410.GL23599@brightrain.aerifal.cx>

On Wed, Jan 16, 2019 at 06:44:10PM -0500, Rich Felker wrote:
> On Wed, Jan 16, 2019 at 03:38:06PM -0600, A. Wilcox wrote:
> > What do you mean by "messy char[] buffer idiom"?  The buffer that is
> > meant to contain the strings is passed to the function (char *buf),
> > *not* returned by it.
> 
> It's also necessarily used to contain the struct itself, despite C not
> really allowing this and the buffer not being properly aligned for it
> (requiring realignment which is inherently nonportable and not even
> possible in something like a memory-safe implementation). A proper API
> would have the caller pass both a pointer to the struct to fill and a
> pointer to char[] space for strings.
> 

Erm, no, there is a parameter where you can store the struct itself.
It's the second parameter. You are supposed to set the target of the
fifth parameter equal to the second on success, else to NULL.

Working on it, but that is even more messy. What to do on EOF? The only
thing I can think of is return 0, but set *spbufp to 0 (wait, is that
the only reason return value and return pointer are split? Dear lord...)

What to do on "buffer too small"? Seek the file back to where it was?

What to return on format error?

What to do on "buffer too large"? I wanted to use fgets() to read the
next line, but the size parameter of fgets() is an int, so the size
parameter to fgetspent_r() can't exceed INT_MAX.

> > I would personally leave the fp where it is (not rewind)
> > since all the other *get*ent functions don't rewind on error either.
> 
> But should it finish consuming the line it's in the middle of?
> Otherwise it could wrongly interpret the remainder of the line as a
> complete line if called again. Note that the current version of the
> non-_r function has that issue if getline OOM's..
> 
> Rich

Good point, that's a possible problem as well. We could rid ourselves of
these problems by declaring a new call after error to be UB. But that's
not QoI...

Ciao,
Markus


  reply	other threads:[~2019-01-17  5:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 19:21 A. Wilcox
2019-01-16 20:50 ` Rich Felker
2019-01-16 21:38   ` A. Wilcox
2019-01-16 23:44     ` Rich Felker
2019-01-17  5:31       ` Markus Wichmann [this message]
2019-01-17 15:38         ` Rich Felker
2019-01-18 20:37           ` Markus Wichmann
2019-01-20 15:41             ` Markus Wichmann
2019-01-20 21:12               ` A. Wilcox
2019-01-21  0:50                 ` Rich Felker
2019-01-20 22:02               ` A. Wilcox

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=20190117053147.GH29911@voyager \
    --to=nullplan@gmx.net \
    --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).