Re: [PATCH v2] newlib: libc: Fix bugs in the commit 3d94e07c49b5.
Corinna Vinschen <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
On Nov 16 14:19, Corinna Vinschen wrote:
> On Nov 16 21:27, Takashi Yano wrote:
> > 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?
Yes, I did. The _getchar_unlocked and _putchar_unlocked macros as well
as the __SINGLE_THREAD__ getc and putc macros(*). I also missed the
putc{har}_unlocked and getc{har}_unlocked functions.
They all call __sgetc_r or __sputs_r, both being macros in stdio.h.
The underlying functions __srget_r and __swbuf_r are shared between
byte and wide-char orientation functions.
Drat. Looks like we really have to do the ORIENT stuff inside the
__sgetc_r/__sputs_r macros...
Corinna
(*) I'm deliberately ignoring the fast_putc macro. It's so much beyond
standards and old as dirt. I wonder if we shouldn't remove it.