mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
fdtget: Fix signedness comparisons warnings
With -Wsign-compare, compilers warn about a mismatching signedness in the different legs of the conditional operator, in fdtget.c. In the questionable expression, we are constructing a 16-bit value out of two unsigned 8-bit values, however are relying on the compiler's automatic expansion of the uint8_t to a larger type, to survive the left shift. This larger type happens to be an "int", so this part of the expression becomes signed. Fix this by explicitly blowing up the uint8_t to a larger *unsigned* type, before doing the left shift. And while we are at it, convert the hardly readable conditional operator usage into a sane switch/case expression. This fixes "make fdtget", when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-3-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
d966f08fcd
commit
9102211855
2 changed files with 15 additions and 2 deletions
10
fdtget.c
10
fdtget.c
|
@ -62,8 +62,14 @@ static int show_cell_list(struct display_info *disp, const char *data, int len,
|
|||
for (i = 0; i < len; i += size, p += size) {
|
||||
if (i)
|
||||
printf(" ");
|
||||
value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
|
||||
size == 2 ? (*p << 8) | p[1] : *p;
|
||||
switch (size) {
|
||||
case 4: value = fdt32_ld((const fdt32_t *)p); break;
|
||||
case 2: value = fdt16_ld((const fdt16_t *)p); break;
|
||||
case 1:
|
||||
default:
|
||||
value = *p;
|
||||
break;
|
||||
}
|
||||
printf(fmt, value);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue