This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: bug in btowc(0)
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Tue, 6 Apr 2010 16:53:58 +0200
- Subject: Re: bug in btowc(0)
- References: <4BBA68DF.1070700@redhat.com> <20100406080416.GO18530@calimero.vinschen.de> <4BBB3287.9020905@redhat.com>
- Reply-to: newlib at sourceware dot org
On Apr 6 07:09, Eric Blake wrote:
> On 04/06/2010 02:04 AM, Corinna Vinschen wrote:
> > On Apr 5 16:49, Eric Blake wrote:
> >> On the gnulib list, it was pointed out that cygwin btowc has a bug:
> >>
> >> +#include <stdio.h>
> >> +#include <string.h>
> >> +#include <wchar.h>
> >> +int main ()
> >> +{
> >> + if (btowc ('\0') != 0)
> >> + return 1;
> >> + return 0;
> >> +}
> >>
> >> should have status 0, because NUL is an ASCII byte. Right now, btowc is
> >> mistakenly returning WEOF and this program has status 1.
> >
> > That's a newlib problem. Please send the bug report to the newlib
> > list, for the records. This patch should help:
> >
> > Index: libc/stdlib/btowc.c
> > ===================================================================
> > RCS file: /cvs/src/src/newlib/libc/stdlib/btowc.c,v
> > retrieving revision 1.3
> > diff -u -p -r1.3 btowc.c
> > --- libc/stdlib/btowc.c 18 Nov 2009 09:49:57 -0000 1.3
> > +++ libc/stdlib/btowc.c 6 Apr 2010 08:02:37 -0000
> > @@ -13,6 +13,9 @@ btowc (int c)
> > wchar_t pwc;
> > unsigned char b;
> >
> > + if (c == EOF)
> > + return WEOF;
> > +
> > b = (unsigned char)c;
> >
> > /* Put mbs in initial state. */
> > @@ -22,8 +25,8 @@ btowc (int c)
> >
> > retval = __mbtowc (_REENT, &pwc, &b, 1, __locale_charset (), &mbs);
> >
> > - if (c == EOF || retval != 1)
> > + if (retval != 0 && retval != 1)
> > return WEOF;
> > - else
> > - return (wint_t)pwc;
> > +
> > + return (wint_t)pwc;
> > }
> >
> >
> > Corinna
> >
>
> For what it's worth, Corinna's patch looks good to me.
I've applied this patch.
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat