[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#231461: libc6: iconv skips unconvertible character when converting from windows-1258



Package: libc6
Version: 2.2.5-11.5
Severity: normal

#include <assert.h>
#include <iconv.h>
#include <stdio.h>
#include <string.h>

void test(char *str, char *from, char *to)
{
  char *ib, *ob;
  size_t ibl, obl, ret;
  char buf[100];
  iconv_t cd;

  printf("\nConverting from %s to %s\n", from, to);
  cd = iconv_open(to, from);
  if (cd == (iconv_t)-1) {
    printf("iconv_open failed\n");
    return;
  }
  ib = str;
  ibl = strlen(str);
  ob = buf;
  obl = sizeof(buf);
  ret = iconv(cd, &ib, &ibl, &ob, &obl);
  printf("iconv returned %d\n", ret);
  assert(ib + ibl == str + strlen(str));
  assert(ob + obl == buf + sizeof(buf));
  printf("Read %d bytes and wrote %d bytes\n", ib - str, ob - buf);
  iconv_close(cd);
}

int main()
{
  test("v\x9cux", "windows-1258", "ISO-8859-1");
  test("v\xc5\x93ux", "utf-8", "ISO-8859-1");
  return 0;
}

/*
  With glibc-2.2.5 on Debian I obtained the following output:

Converting from windows-1258 to ISO-8859-1
iconv returned -1
Read 2 bytes and wrote 1 bytes

Converting from utf-8 to ISO-8859-1
iconv returned -1
Read 1 bytes and wrote 1 bytes

  When converting from windows-1258, the unconvertable character is skipped.
  When converting from utf-8, the unconvertable character is not skipped.
*/

-- System Information
Debian Release: 3.0
Kernel Version: Linux dueto.rano1.org 2.4.18-1-686 #1 Mon Jan 5 19:32:08 UTC 2004 i686 unknown




Reply to: