From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7817 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: stdio fixes & internals documentation Date: Thu, 28 May 2015 23:05:16 -0400 Message-ID: <20150529030516.GB17573@brightrain.aerifal.cx> References: <20150529013937.GA32093@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1432868737 12867 80.91.229.3 (29 May 2015 03:05:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 29 May 2015 03:05:37 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7829-gllmg-musl=m.gmane.org@lists.openwall.com Fri May 29 05:05:31 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YyAby-0005zg-Vv for gllmg-musl@m.gmane.org; Fri, 29 May 2015 05:05:31 +0200 Original-Received: (qmail 27723 invoked by uid 550); 29 May 2015 03:05:29 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 27702 invoked from network); 29 May 2015 03:05:28 -0000 Content-Disposition: inline In-Reply-To: <20150529013937.GA32093@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:7817 Archived-At: On Thu, May 28, 2015 at 09:39:37PM -0400, Rich Felker wrote: > The first thing I want to do is fix the known bug in ungetc, and I > think the easiest way to do that is to make __toread set valid read > buffer pointers when it fails due to eof status. Then, instead of > ungetc checking the return value of __toread, it can instead call > __toread and then just check rpos. That is, instead of: > > if ((!f->rend && __toread(f)) || f->rpos <= f->buf - UNGET) { > // error > > it can instead do: > > if (!f->rend) __toread(f); > if (f->rpos <= f->buf - UNGET) { > // error > > or perhaps: > > if (!f->rpos) __toread(f); > if (!f->rpos || f->rpos <= f->buf - UNGET) { > // error > > I like the second version better because it does not assume that a > null pointer compares <= any valid pointer, which could be wrong if > pointer <= is implemented as a signed comparison. [...] I have a fix ready to commit here, but sometime between now and release I think we need some tests for it. The immportant things to test are that ungetc and ungetwc work correctly on newly-opened files, files in the middle of reading from the buffer, and files at eof; that they fail for files not opened in a mode compatible with reading; and that the new __toread behavior doesn't allow getc or fread to read when the eof flag is set for the file but the underlying fd has more data available (in the real world this only happens on terminals or growing files; the latter would be easier to test I think). Rich