From: Bruno Haible Date: Wed, 28 Mar 2007 21:50:51 +0000 (+0000) Subject: Distinguish invalid and incomplete UTF-8 input, and set errno accordingly. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e213ad01832156fe83f3455195bfe3e1923637de;p=pspp Distinguish invalid and incomplete UTF-8 input, and set errno accordingly. --- diff --git a/ChangeLog b/ChangeLog index f6fc6eba13..d9107b9576 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-03-28 Bruno Haible + + * lib/striconveh.c (mem_cd_iconveh_internal): Use u8_mbtoucr instead + of u8_mbtouc in order to distinguish invalid and incomplete UTF-8 + input. + * modules/striconveh (Depends-on): Add unistr/u8-mbtoucr. Replace + utf8-ucs4 with unistr/u8-mbtouc. Replace ucs4-utf8 with + unistr/u8-uctomb. + 2007-03-28 Bruno Haible * modules/unistr/u8-mbtoucr: New file. diff --git a/lib/striconveh.c b/lib/striconveh.c index 8bee60ae8b..4da14722e6 100644 --- a/lib/striconveh.c +++ b/lib/striconveh.c @@ -479,16 +479,13 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, int n; int m; - n = u8_mbtouc (&uc, (const uint8_t *) in1ptr, in1size); - if (uc == 0xfffd - && !(n >= 3 - && (uint8_t)in1ptr[0] == 0xEF - && (uint8_t)in1ptr[1] == 0xBF - && (uint8_t)in1ptr[2] == 0xBD)) + n = u8_mbtoucr (&uc, (const uint8_t *) in1ptr, in1size); + if (n < 0) { + errno = (n == -2 ? EINVAL : EILSEQ); + n = u8_mbtouc (&uc, (const uint8_t *) in1ptr, in1size); in1ptr += n; in1size -= n; - errno = EILSEQ; res1 = (size_t)(-1); incremented1 = true; break; diff --git a/modules/striconveh b/modules/striconveh index 6b930873b1..172cd854b3 100644 --- a/modules/striconveh +++ b/modules/striconveh @@ -8,10 +8,11 @@ lib/striconveh.c Depends-on: stdbool iconv -utf8-ucs4 -ucs4-utf8 unistr/u8-prev unistr/u8-mbtouc-unsafe +unistr/u8-mbtouc +unistr/u8-mbtoucr +unistr/u8-uctomb strdup c-strcase c-strcaseeq