From cf970a32156e60e8842c5e9e82a3cb147dacaf64 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 23 Aug 2000 05:52:43 +0000 Subject: [PATCH] Update. * iconvdata/sjis.c: In conversion from UCS4, correct test for enough room in target buffer. Patch by KUSANO Takayuki [PR libc/1865]. * iconvdata/bug-iconv1.c: New file. * iconvdata/Makefile (tests): Add bug-iconv1. --- ChangeLog | 6 ++++++ iconvdata/Makefile | 2 ++ iconvdata/bug-iconv1.c | 40 ++++++++++++++++++++++++++++++++++++++++ iconvdata/sjis.c | 7 ++++--- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 iconvdata/bug-iconv1.c diff --git a/ChangeLog b/ChangeLog index cb3009a041..da70260fa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2000-08-22 Ulrich Drepper + * iconvdata/sjis.c: In conversion from UCS4, correct test for + enough room in target buffer. + Patch by KUSANO Takayuki [PR libc/1865]. + * iconvdata/bug-iconv1.c: New file. + * iconvdata/Makefile (tests): Add bug-iconv1. + * locale/iso-4217.def: Update entry for Nicaragua. 2000-08-22 Mark Kettenis diff --git a/iconvdata/Makefile b/iconvdata/Makefile index 2d5cbbea70..34c3f52f0d 100644 --- a/iconvdata/Makefile +++ b/iconvdata/Makefile @@ -49,6 +49,8 @@ modules := ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 \ modules.so := $(addsuffix .so, $(modules)) +tests = bug-iconv1 + include ../Makeconfig libJIS-routines := jis0201 jis0208 jis0212 diff --git a/iconvdata/bug-iconv1.c b/iconvdata/bug-iconv1.c new file mode 100644 index 0000000000..76bcee9183 --- /dev/null +++ b/iconvdata/bug-iconv1.c @@ -0,0 +1,40 @@ +/* Test program by Satoru Takabayashi. */ +#include +#include +#include +#include +#include + +int +main (int argc, char **argv) +{ + const char in[] = "\x41\x42\x43\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"; + /* valid eucJP string */ + const char exp[] = "\x41\x42\x43\x82\xa0\x82\xa2\x82\xa4"; + size_t outbufsize = 10; + /* 10 is too small to store full result (intentional) */ + size_t inleft, outleft; + char *in_p = (char *) in; + char out[outbufsize]; + char *out_p = out; + iconv_t cd; + int i; + + inleft = strlen (in); + outleft = outbufsize; + + cd = iconv_open ("SJIS", "eucJP"); + if (cd == (iconv_t) -1) + { + puts ("iconv_open failed"); + exit (1); + } + + iconv (cd, &in_p, &inleft, &out_p, &outleft); /* this returns E2BIG */ + for (i = 0; i < outbufsize - outleft; ++i) + printf (" %02x", (unsigned char) out[i]); + puts (""); + iconv_close (cd); + + return outbufsize - outleft != 9 || memcmp (out, exp, 9) != 0; +} diff --git a/iconvdata/sjis.c b/iconvdata/sjis.c index 8d907b863c..244cec6db4 100644 --- a/iconvdata/sjis.c +++ b/iconvdata/sjis.c @@ -4484,18 +4484,19 @@ static const char from_ucs4_extra[0x100][2] = } \ else \ { \ - *outptr++ = cp[0]; \ + *outptr = cp[0]; \ /* Now test for a possible second byte and write this if possible. */\ if (cp[1] != '\0') \ { \ - if (__builtin_expect (outptr >= outend, 0)) \ + if (__builtin_expect (outptr + 1 >= outend, 0)) \ { \ /* The result does not fit into the buffer. */ \ result = __GCONV_FULL_OUTPUT; \ break; \ } \ - *outptr++ = cp[1]; \ + *++outptr = cp[1]; \ } \ + ++outptr; \ } \ \ inptr += 4; \