From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13612 Path: news.gmane.org!.POSTED!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: function: fgetspent_r Date: Thu, 17 Jan 2019 06:31:47 +0100 Message-ID: <20190117053147.GH29911@voyager> References: <4ac5ac1b-217f-442f-fc35-bfbf015287bb@adelielinux.org> <20190116205046.GK23599@brightrain.aerifal.cx> <20190116234410.GL23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1547703032 6524 195.159.176.226 (17 Jan 2019 05:30:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 17 Jan 2019 05:30:32 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-13628-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jan 17 06:30:27 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gk0G3-0001Yi-P0 for gllmg-musl@m.gmane.org; Thu, 17 Jan 2019 06:30:27 +0100 Original-Received: (qmail 23562 invoked by uid 550); 17 Jan 2019 05:32:37 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 22518 invoked from network); 17 Jan 2019 05:32:36 -0000 Content-Disposition: inline In-Reply-To: <20190116234410.GL23599@brightrain.aerifal.cx> X-Provags-ID: V03:K1:eq4SbGKizUAcBaraUW2+L1id8ikTAzFC0TRwCNrIS1ytKAANsR5 IBhHf54kGzyCurFFunoPPOZJyR+YgzMCU1JkATEVL/SHIwnc9cGImKwlRfd5QFsITHFav1p UaRXrR/XskweU6yFGKQCHxqzKGlu+b3pRTaBwcQK1BS6RsFhw3hVAGaX+tNDVRqxo/lxB8E EwL1wYuiC0992+/wtIv4Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:gW6/mdYN8qE=:a0r6dRBV3zpAa8JdVRoMKd WD4ivnRsi6buggy1qZ69PzbpQk+P5kpfHc4IYoTwFa45CCL5pPZM13SOnLKxbLNkfKOvqfqun JCfFCUiXkIlXCZsfxgNupi50bZbyv7SNci6CXDN/jq+c1ir7OYUfAcewcdkPaNJ0aUQyZsxiz do+sdAWPMzTneUFuC1gI0cAQVSmA80Zmuvu8bJ8yOJI3FjFSIJVdaNOfcbDZ/NFa3GQGCn7wh /A1JCaTdgC85j/y32zLvhguHpHupgf6kEbxOXsl8/z1fxYVIFFNPlA+ioSFmhxN3xbEuN45Hr hKkrDK1Ab1YbNE7fExn/QmYoGrvfEqst5Ekaye1/NVa1dH3n8C+aHIkj8/j/6dpYzbJAKXfJG N+Dlvy2iJ8xSuF6kQDPPYhxmMWg3vEF1RkxbUGIpDgxtIG/csXDU44hHOFMUhvi3CZ0krJz2q PsPsUncIroetcR9x0/iFpIulQX26yB0CbCeyc7BRqYld2Yg1p8aRN6yPw3c6xx4Kd2APFVfXj 7EZSUBCKq0nTwsNfNgI1Ea5+b7RKQwoepLW3jhhux4dndZA5s2d+864Ke2z0scTdK7QyoduV9 +5X5NOB+HK2tJmINZr343lyZR/pccJc28Y4FPShxWfXf9+3NHFcHClYbUKsnFoRbS1WDJxnzW gSSM//6DgUN04rpeKWIGPCA3VgFr/2F8xt7Sj+IJnUAX1Jtfy/QDooKWnryf3UwuGJKH82ObU dZxjckLXaINZtiXrE/sWXpyX0Og8jYc3FQxfexMoq+bM3cGadpvZ4vVZCb3dSGNbdSMp7UUY Xref: news.gmane.org gmane.linux.lib.musl.general:13612 Archived-At: 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