Fix rare bug in iconv conversion.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17080 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-07-01 08:33:22 +00:00
parent 649d9d7374
commit a8fd582a87
2 changed files with 38 additions and 4 deletions

View file

@ -1,3 +1,9 @@
2003-07-01 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unicode.m: Flush iconv buffer at end of conversion
to handle obscure cases where it says it has converted all the input
sequence, but hasn't written all the output.
2003-06-30 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unicode.m: Add 'UTF-7' so iconv can be used to

View file

@ -1240,6 +1240,7 @@ tables:
size_t rval;
iconv_t cd;
const char *estr = iconv_stringforencoding(enc);
BOOL done = NO;
/* explicitly check for empty encoding name since some systems
* have buggy iconv_open() code which succeeds on an empty name.
@ -1250,6 +1251,10 @@ tables:
result = NO;
break;
}
if (slen == 0)
{
break; // Nothing to do
}
cd = iconv_open(UNICODE_ENC, estr);
if (cd == (iconv_t)-1)
{
@ -1263,7 +1268,7 @@ tables:
inbytesleft = slen;
outbuf = (char*)ptr;
outbytesleft = bsize * sizeof(unichar);
while (inbytesleft > 0)
while (done == NO)
{
if (dpos >= bsize)
{
@ -1273,7 +1278,16 @@ tables:
outbuf = (char*)&ptr[dpos];
outbytesleft += (bsize - old) * sizeof(unichar);
}
rval = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (inbytesleft == 0)
{
done = YES; // Flush iconv, then terminate.
rval = iconv(cd, 0, 0, &outbuf, &outbytesleft);
}
else
{
rval = iconv(cd,
&inbuf, &inbytesleft, &outbuf, &outbytesleft);
}
dpos = (bsize * sizeof(unichar) - outbytesleft) / sizeof(unichar);
if (rval == (size_t)-1)
{
@ -1816,6 +1830,7 @@ tables:
size_t outbytesleft;
size_t rval;
const char *estr = iconv_stringforencoding(enc);
BOOL done = NO;
/* explicitly check for empty encoding name since some systems
* have buggy iconv_open() code which succeeds on an empty name.
@ -1826,6 +1841,10 @@ tables:
result = NO;
break;
}
if (slen == 0)
{
break; // Nothing to convert.
}
cd = iconv_open(estr, UNICODE_ENC);
if (cd == (iconv_t)-1)
{
@ -1839,7 +1858,7 @@ tables:
inbytesleft = slen * sizeof(unichar);
outbuf = (char*)ptr;
outbytesleft = bsize;
while (inbytesleft > 0)
while (done == NO)
{
if (dpos >= bsize)
{
@ -1849,7 +1868,16 @@ tables:
outbuf = (char*)&ptr[dpos];
outbytesleft += (bsize - old);
}
rval = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (inbytesleft == 0)
{
done = YES; // Flush buffer, then terminate.
rval = iconv(cd, 0, 0, &outbuf, &outbytesleft);
}
else
{
rval = iconv(cd,
&inbuf, &inbytesleft, &outbuf, &outbytesleft);
}
dpos = bsize - outbytesleft;
if (rval != 0)
{