diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-03-26 08:10:58 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-03-26 08:10:58 +0000 |
commit | c657f8b3ff63aab7badd86d8aaee3ebb5eb7f557 (patch) | |
tree | 0c6df2ed25d08ab94883d1ef6a046b6cb5eaa979 | |
parent | 83e886a32ada14d1d671b51225aea29ed453a131 (diff) | |
download | glibc-c657f8b3ff63aab7badd86d8aaee3ebb5eb7f557.tar.gz glibc-c657f8b3ff63aab7badd86d8aaee3ebb5eb7f557.tar.xz glibc-c657f8b3ff63aab7badd86d8aaee3ebb5eb7f557.zip |
Test for EUC-TW bug with too-short output buffers.
-rw-r--r-- | iconvdata/bug-iconv4.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/iconvdata/bug-iconv4.c b/iconvdata/bug-iconv4.c new file mode 100644 index 0000000000..f6bfebd39f --- /dev/null +++ b/iconvdata/bug-iconv4.c @@ -0,0 +1,78 @@ +/* Contributed by Jiro SEKIBA <jir@yamato.ibm.com>. */ +#include <errno.h> +#include <iconv.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define UCS_STR "\x4e\x8c" /* EUC-TW 0xa2a2, EUC-JP 0x */ + +static const char *to_code; + +static bool +xiconv (iconv_t cd, int out_size) +{ + unsigned char euc[4]; + char *inp = (char *) UCS_STR; + char *outp = euc; + size_t inbytesleft = strlen (UCS_STR); + size_t outbytesleft = out_size; + size_t ret; + bool fail = false; + + errno = 0; + ret = iconv (cd, &inp, &inbytesleft, &outp, &outbytesleft); + if (errno || ret == (size_t) -1) + { + fail = out_size == 4 || errno != E2BIG; + printf ("expected %d (E2BIG), got %d (%m)\n", E2BIG, errno); + } + else + { + printf ("%s: 0x%02x%02x\n", to_code, euc[0], euc[1]); + if (out_size == 1) + fail = true; + } + + return fail; +} + + +static iconv_t +xiconv_open (const char *code) +{ + iconv_t cd; + to_code = code; + errno = 0; + if (errno || (cd = iconv_open (to_code, "UCS-2BE")) == (iconv_t) -1) + { + puts ("Can't open converter"); + exit (1); + } + return cd; +} + + +int +main (void) +{ + iconv_t cd; + int result = 0; + + cd = xiconv_open ("EUC-TW"); + result |= xiconv (cd, 4) == true; + puts ("---"); + result |= xiconv (cd, 1) == true; + puts ("---"); + iconv_close (cd); + + cd = xiconv_open ("EUC-JP"); + result |= xiconv (cd, 4) == true; + puts ("---"); + result |= xiconv (cd, 1) == true; + puts ("---"); + iconv_close (cd); + + return result; +} |