git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: t3900 failure on macOS, iconv(3) broken?

From
René Scharfe <l.s.r@web.de>
Date
Dec 9, 2025, 19:35 UTC
Message-ID
<51dc4ca7-61fd-42f7-8e72-a516a870e011@web.de>
In-Reply-To
<20251209163356.GA5762@tb-raspi4>
On 12/9/25 5:33 PM, Torsten Bögershausen wrote:
Show 29 quoted lines
> On Mon, Dec 08, 2025 at 11:59:11PM +0100, René Scharfe wrote:
>>
>> diff --git a/utf8.c b/utf8.c
>> index 35a0251939..ff0c541fbc 100644
>> --- a/utf8.c
>> +++ b/utf8.c
>> @@ -515,6 +515,19 @@ char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,
>>  			out = xrealloc(out, outalloc);
>>  			outpos = out + sofar;
>>  			outsz = outalloc - sofar - 1;
>> +#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;
>> +			cp = (iconv_ibp)in;
>> +			outpos = out + bom_len;
>> +			outsz = outalloc - bom_len - 1;
>> +			iconv(conv, NULL, NULL, NULL, NULL);
>> +#endif
>>  		}
>>  		else {
>>  			*outpos = '\0';
> 
> 
> I am not sure, if I understand the second call to iconv(NULL....)

It resets the state of the converter, e.g. the current code page of encodings that have multiple ones.

Show 35 quoted lines
> Here is a slightly different patch.
> Comments wellcome.
> 
> 
> diff --git a/utf8.c b/utf8.c
> index 35a0251939..b3c1dd2b59 100644
> --- a/utf8.c
> +++ b/utf8.c
> @@ -486,10 +486,11 @@ int utf8_fprintf(FILE *stream, const char *format, ...)
>  char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,
>  			    size_t bom_len, size_t *outsz_p)
>  {
> -	size_t outsz, outalloc;
> +	size_t outsz, outalloc, originsz;
>  	char *out, *outpos;
>  	iconv_ibp cp;
>  
> +	originsz = insz;
>  	outsz = insz;
>  	outalloc = st_add(outsz, 1 + bom_len); /* for terminating NUL */
>  	out = xmalloc(outalloc);
> @@ -515,6 +516,17 @@ char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,
>  			out = xrealloc(out, outalloc);
>  			outpos = out + sofar;
>  			outsz = outalloc - sofar - 1;
> +#ifdef __APPLE__
> +			/*
> +			 * Several version of iconv(3) mess up piecemeal conversions.
> +			 * Restore the original pointers, sizes,
> +			 * and converter state, then retry converting
> +			 * the full string using the reallocated buffer.
> +			 */
> +                        insz = originsz;
> +                        outpos = out + bom_len;
> +                        cp = (iconv_ibp)in;

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.

> +#endif
>  		}
>  		else {
>  			*outpos = '\0';
Previous: Torsten BögershausenNext: Torsten Bögershausen
Message 6 of 45 in “t3900 failure on macOS, iconv(3) broken?”
  1. René ScharfeDec 8, 2025
  2. Koji NakamaruDec 9, 2025
  3. Yee Cheng ChinDec 9, 2025
  4. Collin FunkDec 9, 2025
  5. Torsten BögershausenDec 9, 2025
  6. René ScharfeDec 9, 2025
  7. Torsten BögershausenDec 9, 2025
  8. René ScharfeDec 9, 2025
  9. config.mak.uname: use iconv from Homebrew on macOSRené Scharfe, Dec 9, 2025
  10. Yee Cheng ChinDec 9, 2025
  11. René ScharfeDec 9, 2025
  12. Carlo Marcelo Arenas BelónDec 10, 2025
  13. René ScharfeDec 10, 2025
  14. Junio C HamanoDec 11, 2025
  15. Carlo Marcelo Arenas BelónDec 11, 2025
  16. Junio C HamanoDec 12, 2025
  17. René ScharfeDec 12, 2025
  18. Carlo Marcelo Arenas BelónDec 12, 2025
  19. Re* [PATCH] config.mak.uname: use iconv from Homebrew on macOSJunio C Hamano, Dec 12, 2025
  20. René ScharfeDec 12, 2025
  21. Junio C HamanoDec 12, 2025
  22. Torsten BögershausenDec 10, 2025
  23. René ScharfeDec 10, 2025
  24. brian m. carlsonDec 10, 2025
  25. Junio C HamanoDec 11, 2025
  26. Junio C HamanoDec 11, 2025
  27. René ScharfeDec 11, 2025
  28. Junio C HamanoDec 12, 2025
  29. René ScharfeDec 12, 2025
  30. 2/2 config.mak.uname: use iconv from Homebrew on macOSRené Scharfe, Dec 13, 2025
  31. 1/2 Makefile: add NO_HOMEBREWRené Scharfe, Dec 13, 2025
  32. Torsten BögershausenDec 14, 2025
  33. Junio C HamanoDec 14, 2025
  34. Torsten BögershausenDec 14, 2025
  35. Junio C HamanoDec 14, 2025
  36. René ScharfeDec 14, 2025
  37. Junio C HamanoDec 14, 2025
  38. René ScharfeDec 16, 2025
  39. 1/2 macOS: make Homebrew use configurableRené Scharfe, Dec 16, 2025
  40. René ScharfeDec 16, 2025
  41. Torsten BögershausenDec 16, 2025
  42. 2/2 macOS: use iconv from Homebrew if presentRené Scharfe, Dec 16, 2025
  43. 0/2 macOS: use iconv from Homebrew if needed and presentRené Scharfe, Dec 24, 2025
  44. 2/2 macOS: use iconv from Homebrew if needed and presentRené Scharfe, Dec 24, 2025
  45. 1/2 macOS: make Homebrew use configurableRené Scharfe, Dec 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.