Re: [PATCH v2 2/3] configure.ac: define ICONV_OMITS_BOM if necessary

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2019-11-01 12:56:57 -0400, Jeff King wrote:
> On Fri, Nov 01, 2019 at 03:25:10PM +0700, Doan Tran Cong Danh wrote:
> > +	v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
> > +	return v != 0xfe + 0xff;
> 
> I wondered at first why not just:
> 
>   return v[0] != 0xfe || v[1] != 0xff;
> 
> but the answer is that you are catching BOMs of either endianness. We
> might at some point need to distinguish the two,

Yes, it's about catching BOM of either endianess. To distinguish
between LE and BE, it'll be better to use AC_C_BIGENDIAN instead (it's
friendlier for cross-compiling).

Anyway, we couldn't compare out[0] and out[1] with 0xf{e,f} directly
because char could be either signed (-2 and -1) or unsigned (0xfe, 0xff).
We must cast it to unsigned char (required to be 8 bits by POSIX),
then let the integer promotion promote it to int (at least 16 bits).

-- 
Danh



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux