Re: t3900 failure on macOS, iconv(3) broken?
On Tue, Dec 09, 2025 at 08:35:23PM +0100, René Scharfe wrote:
> On 12/9/25 5:33 PM, Torsten Bögershausen wrote:
> > On Mon, Dec 08, 2025 at 11:59:11PM +0100, René Scharfe wrote:
> >>
>
> This forgets to reset outsz and the converter state. With this patch
> t0028-working-tree-encoding.sh seems to get stuck in an endless loop.
Thanks for testing.
I did another test here
(increase the outbuffer with only one byte per round, old MacOs)
and yes, we need to reset iconv.
Back to your patch. I think it is good to go further,
with one or 2 remarks, see TB
out = xrealloc(out, outalloc);
// TB: move into else outpos = out + sofar;
// TB: move into else outsz = outalloc - sofar - 1;
// TB: We have seen different breakages of apple iconv. Should we run the same code
// on all versions of MacOs to be more future proof ?
// and do we need a Makefile knob, if one, and only one platform is affected ?
// I don't know
#ifdef __APPLE__
or
#ifdef ICONV_BREAKS
/*
* If iconv(3) messes up piecemeal conversions
* then restore the original pointers, sizes,
* and converter state, then retry converting
* the full string using the reallocated buffer.
*/
insz += (char *)cp - in; /* TB stumbled here: "in" is "const char *"
And I didn't like the fact that insz is destroyed
and needs to be restored. That is why I had a originsz
(or szinorig ?)
cp = (iconv_ibp)in;
outpos = out + bom_len;
outsz = outalloc - bom_len - 1;
iconv(conv, NULL, NULL, NULL, NULL);
#else
outpos = out + sofar;
outsz = outalloc - sofar - 1;
#endif