[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[screen-devel] suspicious code in encoding.c
From: |
Vincent Lefevre |
Subject: |
[screen-devel] suspicious code in encoding.c |
Date: |
Fri, 18 Feb 2022 02:15:05 +0100 |
User-agent: |
Mutt/2.2+3 (bfa075a3) vl-138565 (2022-02-14) |
When compiling encoding.c from the screen-v4 branch:
encoding.c: In function ‘AddUtf8’:
display.h:322:18: warning: overflow in conversion from ‘int’ to ‘char’ changes
value from ‘c >> 12 & 12288^ 248’ to ‘-8’ [-Woverflow]
322 | *D_obufp++ = (c); \
| ^
encoding.c:682:4: note: in expansion of macro ‘AddChar’
682 | AddChar((c & 0x3000000) >> 12 ^ 0xf8);
| ^~~~~~~
encoding.c: In function ‘ToUtf8’:
encoding.c:727:13: warning: overflow in conversion from ‘int’ to ‘char’ changes
value from ‘c >> 12 & 12288^ 248’ to ‘-8’ [-Woverflow]
727 | *p++ = (c & 0x3000000) >> 12 ^ 0xf8;
| ^
Indeed, the code is really strange:
(c & 0x3000000) >> 12 ^ 0xf8
will be stored in a char. So why dealing with bits more significant
than the 8 bits of a char?
The master branch has a similar code, but with int replaced by
uint32_t, so that the warning disappears just because of the unsigned
type (the behavior becomes fully specified by the C standard instead
of being implementation defined).
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
- [screen-devel] suspicious code in encoding.c,
Vincent Lefevre <=