This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: should mbrtowc(&wc, "", 1, &ps) set wc?
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: Re: should mbrtowc(&wc, "", 1, &ps) set wc?
- From: Edmund GRIMLEY EVANS <edmundo at rano dot org>
- Date: Sat, 11 Nov 2000 21:16:06 +0000
- Bcc: Edmund GRIMLEY EVANS <edmundo at rano dot org>
- References: <20001111165654.J13595@rano.org> <E13ufej-0004d7-00@wisbech.cl.cam.ac.uk>
- Reply-To: edmundo at rano dot org, libc-alpha at sourceware dot cygnus dot com
Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>:
> That sounds indeed like a glibc 2.2 bug then.
And I see you've reported it to the appropriate authorities. Thanks.
I've noticed another thing, that someone might want to call a bug:
In a UTF-8 locale, mbrtowc(&wc, "A", (size_t)(-1), &ps) returns 1, but
mbrtowc(&wc, "\302\240", (size_t)(-1), &ps) returns -1. So does
mbrtowc(&wc, s, (char *)0 - s, &ps), where s is "\302\240", but
mbrtowc(&wc, s, (char *)(-1) - s, &ps) returns 2.
I don't know whether strings are allowed to wrap around the address
space, but the behaviour of mbrtowc is inconsistent in this respect
and might confuse some program.
By the way, http://www-gnats.gnu.org:8080/cgi-bin/wwwgnats.pl,
mentioned in BUGS, doesn't work.
I'm not subscribed to libc-alpha, so please copy replies to me.
Edmund
Program tested on i386-linux:
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
int main()
{
wchar_t wc;
char *s = "\302\240";
mbstate_t ps;
size_t r;
setlocale(LC_ALL, "");
memset(&ps, 0, sizeof(ps));
r = mbrtowc(&wc, "A", (size_t)(-1), &ps);
printf("%ld %ld\n", (long)r, wc);
memset(&ps, 0, sizeof(ps));
r = mbrtowc(&wc, s, (size_t)(-1), &ps);
printf("%ld %ld\n", (long)r, wc);
memset(&ps, 0, sizeof(ps));
r = mbrtowc(&wc, s, (char *)0 - s, &ps);
printf("%ld %ld\n", (long)r, wc);
memset(&ps, 0, sizeof(ps));
r = mbrtowc(&wc, s, (char *)(-1) - s, &ps);
printf("%ld %ld\n", (long)r, wc);
return 0;
}
Output:
$ LANG=eo ./a.out
1 65
-1 65
-1 65
2 160