[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf %d $'"\xff' returns random values in UTF-8 and 0 in C locale
From: |
Chet Ramey |
Subject: |
Re: printf %d $'"\xff' returns random values in UTF-8 and 0 in C locale |
Date: |
Sun, 17 Sep 2017 18:05:55 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
On 9/17/17 6:01 AM, Stephane Chazelas wrote:
> $ locale charmap
> UTF-8
> $ bash -c '"$@"' sh printf '%d\n' $'"\xff' $'"\xff' $'"\xff'
> 32767
> 0
> 0
>
> That's because we store the return value of mblen() (which may be
> -1) into a size_t (unsigned) variable.
>
> See patch below which aligns the behaviour with that of other
> shells which use the byte value when the initial sequence of
> bytes can't be converted to a character.
Thanks for the report. I'll take a look.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/