[PATCH] libftd: incorrect logical constraint in fdt_get_string()

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



For GCC 9.2.1 the negative of an unsigned size_t value is again an unsigned
size_t value, e.g. -5UL = 18446744073709551611UL.

Correct the logical constraint. Add necessary type conversions.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@xxxxxx>
---
It would be advisable to add -Wextra to the libfdt Makefile after
correcting the 50+ -Wsign-compare problems reported.
---
 libfdt/fdt_ro.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index adab0cb..b69806f 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -59,9 +59,9 @@ const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
 		}
 	} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
 		if ((stroffset >= 0)
-		    || (stroffset < -fdt_size_dt_strings(fdt)))
+		    || ((size_t)-stroffset > fdt_size_dt_strings(fdt)))
 			goto fail;
-		if ((-stroffset) < len)
+		if ((size_t)-stroffset < len)
 			len = -stroffset;
 	} else {
 		err = -FDT_ERR_INTERNAL;
--
2.24.0




[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux