This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
wctomb dumps core on invalid input
- To: libc-alpha at sources dot redhat dot com
- Subject: wctomb dumps core on invalid input
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 4 Dec 2000 14:28:49 +0100 (CET)
According to SUSV2, "wctomb() returns -1 if the value of wchar does not
correspond to a valid character". This is not what glibc 2.2 does. Here
is a test program.
===========================================
#include <wchar.h>
#include <locale.h>
int main ()
{
char buf[10];
wchar_t wc = 0xdeadbeef;
setlocale(LC_ALL, "de_DE.UTF-8");
return 1 + wctomb(buf, wc);
}
===========================================
$ ./a.out
a.out: ../iconv/loop.c:267: internal_utf8_loop: Zusicherung »wc <= 0x7fffffff« nicht erfüllt.
Abgebrochen (core dumped)
It's annoying because it makes Motif demo programs dump core in UTF-8 locales.
Bruno
2000-12-03 Bruno Haible <haible@clisp.cons.org>
* iconv/gconv_simple.c (__gconv_transform_internal_utf8): Use usual
error treatment when an invalid wide character is encountered.
*** glibc-2.2/iconv/gconv_simple.c.bak Tue Sep 19 00:42:24 2000
--- glibc-2.2/iconv/gconv_simple.c Sun Dec 3 18:08:33 2000
***************
*** 829,838 ****
{ \
uint32_t wc = *((uint32_t *) inptr); \
\
! /* Since we control every character we read this cannot happen. */ \
! assert (wc <= 0x7fffffff); \
\
! if (wc < 0x80) \
/* It's an one byte sequence. */ \
*outptr++ = (unsigned char) wc; \
else \
--- 829,846 ----
{ \
uint32_t wc = *((uint32_t *) inptr); \
\
! if (__builtin_expect (wc > 0x7fffffff, 0)) \
! { \
! /* An invalid wide character, e.g. invalid argument to wcrtomb. */ \
! if (! ignore_errors_p ()) \
! { \
! result = __GCONV_ILLEGAL_INPUT; \
! break; \
! } \
\
! ++*irreversible; \
! } \
! else if (wc < 0x80) \
/* It's an one byte sequence. */ \
*outptr++ = (unsigned char) wc; \
else \
***************
*** 866,871 ****
--- 874,880 ----
\
inptr += 4; \
}
+ #define LOOP_NEED_FLAGS
#include <iconv/loop.c>
#include <iconv/skeleton.c>