[PATCH 1/2] Show 4 byte UTF-8 as \Uxxxxxxxx Simplify this by using a single uint32 rather than four bytes.

Andrew C Aitchison werdna@aitchison.me.uk
Tue Sep 9 19:56:10 GMT 2025


On Tue, 9 Sep 2025, Andrew C Aitchison wrote:

> ---
> binutils/doc/binutils.texi | 32 +++++++++++++++++---------------
> binutils/nm.c              |  9 +++++----
> binutils/objdump.c         |  9 +++++----
> binutils/readelf.c         | 10 +++++-----
> binutils/strings.c         |  2 +-
> 5 files changed, 33 insertions(+), 29 deletions(-)

> diff --git a/binutils/objdump.c b/binutils/objdump.c
> index 34199e30ab8..7fc7b6fb86d 100644
> --- a/binutils/objdump.c
> +++ b/binutils/objdump.c
> @@ -658,10 +658,11 @@ display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
> 	  break;
>
> 	case 4:
> -	  out += sprintf (out, "\\u%02x%02x%02x",
> -		  ((in[0] & 0x07) << 2) | ((in[1] & 0x30) >> 4),
> -		  ((in[1] & 0x0f) << 4) | ((in[2] & 0x3c) >> 2),
> -		  ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
> +	  out += sprintf (out, "\\U%08x",
> +		  ((out[0] & 0x07) << 18) |
> +		  ((out[1] & 0x3f) << 12) |
> +		  ((out[2] & 0x3f) << 6) |
> +		  ((out[3] & 0x3f)) );

This is wrong.
We should be calculating with the values of in[] no out[].

I will cut a full new set of patches.

-- 
Andrew C. Aitchison                      Kendal, UK
                    andrew@aitchison.me.uk


More information about the Binutils mailing list