[rtems commit] fdtget: Fix signedness comparisons warnings

Sebastian Huber sebh at rtems.org
Thu Dec 16 13:58:33 UTC 2021


Module:    rtems
Branch:    master
Commit:    c07e23899bfee7df5de107ceceb4e76ccb324763
Changeset: http://git.rtems.org/rtems/commit/?id=c07e23899bfee7df5de107ceceb4e76ccb324763

Author:    Andre Przywara <andre.przywara at arm.com>
Date:      Fri Jun 18 18:20:27 2021 +0100

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 at arm.com>
Message-Id: <20210618172030.9684-3-andre.przywara at arm.com>
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>

---

 cpukit/include/libfdt.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index 73467f7..7f117e8 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -131,6 +131,13 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
  * to work even with unaligned pointers on platforms (such as ARMv5) that don't
  * like unaligned loads and stores.
  */
+static inline uint16_t fdt16_ld(const fdt16_t *p)
+{
+	const uint8_t *bp = (const uint8_t *)p;
+
+	return ((uint16_t)bp[0] << 8) | bp[1];
+}
+
 static inline uint32_t fdt32_ld(const fdt32_t *p)
 {
 	const uint8_t *bp = (const uint8_t *)p;



More information about the vc mailing list