public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH v2] newlib: libc: Fix bugs in the commit 3d94e07c49b5.
Date: Thu, 16 Nov 2023 14:19:13 +0100	[thread overview]
Message-ID: <ZVYW0fAm8+IPFCSC@calimero.vinschen.de> (raw)
In-Reply-To: <20231116212723.45c488a9177ab05b922ee901@nifty.ne.jp>

Hi Takashi,

On Nov 16 21:27, Takashi Yano wrote:
> Hi Corinna,
> 
> On Wed, 15 Nov 2023 17:31:39 +0100
> Corinna Vinschen wrote:
> > Hi Takashi,
> > 
> > On Nov 13 14:07, Corinna Vinschen wrote:
> > > On Nov 11 01:09, Takashi Yano wrote:
> > > > diff --git a/newlib/libc/stdio/ungetc.c b/newlib/libc/stdio/ungetc.c
> > > > index 79914af08..5053fd6c4 100644
> > > > --- a/newlib/libc/stdio/ungetc.c
> > > > +++ b/newlib/libc/stdio/ungetc.c
> > > > @@ -125,12 +125,6 @@ _ungetc_r (struct _reent *rptr,
> > > >  
> > > >    _newlib_flockfile_start (fp);
> > > >  
> > > > -  if (ORIENT (fp, -1) != -1)
> > > > -    {
> > > > -      _newlib_flockfile_exit (fp);
> > > > -      return EOF;
> > > > -    }
> > > > -
> > > >    /* After ungetc, we won't be at eof anymore */
> > > >    fp->_flags &= ~__SEOF;
> > > >  
> > > > @@ -213,6 +207,8 @@ int
> > > >  ungetc (int c,
> > > >         register FILE *fp)
> > > >  {
> > > > +  if (ORIENT (fp, -1) != -1)
> > > > +    return EOF;
> > > >    return _ungetc_r (_REENT, c, fp);
> > > >  }
> > > >  #endif /* !_REENT_ONLY */
> > > 
> > > As per the reasoning in terms of old standards, we shouldn't check or set
> > > the orientation in ungetc at all.
> > 
> > Given all that has been discussed, I attached a followup proposal.
> > I hope that's ok.  We may want to release 3.4.10 in the next weeks.
> 
> LGTM, except for:
> 1) Shouldn't we add flags2 = 0 also for _fmemopen_r(), _fopencookie_r(),
>    _funopen_r() and internal_open_memstream_r()?

Not necessary.  All three functions get the FILE* from a call to __sfp,
which always sets _flags2 to 0 anyway.

> 2) __swbuf_r() has ORIENT (fp, -1) call, however, result is not checked.

Good catch.  Looks like setting the orientation at this point is
wrong.  __swbuf_r is called via the __sputc_r macro in stdio.h.
But __sputc_r is also called from __fputwc as well as, potentially,
from _fputws_r.

AFAICS, we already set the orientation from the calling functions
_putc_r (covering putchar, putc, fputc) and from _puts_r as
well as _fputs_r (covering puts, fputs).

On the wide-char side, we set the orientation from _fputwc_r
(covering putwchar, putwc, fputwc) and from _fputws_r (covering
fputws).

So I *think* we can safely remove the ORIENT call from __swbuf_r,
or did I miss some other way to call __swbuf_r?


Thanks,
Corinna


  reply	other threads:[~2023-11-16 13:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 16:09 Takashi Yano
2023-11-13 13:07 ` Corinna Vinschen
2023-11-15 16:31   ` Corinna Vinschen
2023-11-15 22:53     ` Brian Inglis
2023-11-16  9:34       ` Corinna Vinschen
2023-11-16 12:27     ` Takashi Yano
2023-11-16 13:19       ` Corinna Vinschen [this message]
2023-11-16 13:48         ` Corinna Vinschen
2023-11-16 14:08           ` Corinna Vinschen
2023-11-20 20:08             ` Corinna Vinschen

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=ZVYW0fAm8+IPFCSC@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --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).