Distinguish invalid and incomplete UTF-8 input, and set errno accordingly.
authorBruno Haible <bruno@clisp.org>
Wed, 28 Mar 2007 21:50:51 +0000 (21:50 +0000)
committerBruno Haible <bruno@clisp.org>
Wed, 28 Mar 2007 21:50:51 +0000 (21:50 +0000)
ChangeLog
lib/striconveh.c
modules/striconveh

index f6fc6eba13f444ba2831a4bcb1e2c309964cae18..d9107b9576fba4cbfeddb0d46adf14cc75c2f601 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-03-28  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * modules/unistr/u8-mbtoucr: New file.
index 8bee60ae8b81c6d6ec40979b24135fe588625f09..4da14722e66cf814357ca70dd519590d27fdcc2d 100644 (file)
@@ -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;
index 6b930873b1b1e569eff073091ef622ab4e9c6500..172cd854b3a6fe05d7e317970c89298844d22a3a 100644 (file)
@@ -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