The E2BIG case tries to restart the whole conversion, by reinitializing
all variables to their initial states. However the value of 'text' might
already have been advanced somewhat if there was a previous loop for e.g.
an invalid character. This commit fixes the problem by keeping the
original 'text' around and using a moving input pointer instead.
char *outbuf = 0;
size_t outbufferlength;
size_t result;
+ char *ip;
char *op ;
size_t inbytes = 0;
size_t outbytes ;
if ( outbufferlength > length)
break;
+ ip = text;
+
outbuf = pool_malloc (pool, outbufferlength);
op = outbuf;
do {
- const char *ip = text;
- result = iconv (conv, (ICONV_CONST char **) &text, &inbytes,
+ result = iconv (conv, (ICONV_CONST char **) &ip, &inbytes,
&op, &outbytes);
if ( -1 == result )
op = outbuf;
outbytes = outbufferlength;
inbytes = length;
- text = ip;
+ ip = text;
break;
default:
/* should never happen */