[PATCH 1/1] libfdt: incorrect logical constraint in fdt_strerror()

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



With GCC 9.2.1 '-FDT_ERRTABSIZE' is of type long unsigned int so it is
always a positive number.

This becomes easily visible when adding -Wextra to the compiler flags:

libfdt/fdt_strerror.c:51:18: warning: comparison of integer expressions
of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
   51 |  else if (errval > -FDT_ERRTABSIZE) {

So (errval > -FDT_ERRTABSIZE) is always false in contrast to what the
developer intended.

Add the missing type conversion.

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

diff --git a/libfdt/fdt_strerror.c b/libfdt/fdt_strerror.c
index 768db66..c02c6ef 100644
--- a/libfdt/fdt_strerror.c
+++ b/libfdt/fdt_strerror.c
@@ -48,7 +48,7 @@ const char *fdt_strerror(int errval)
 		return "<valid offset/length>";
 	else if (errval == 0)
 		return "<no error>";
-	else if (errval > -FDT_ERRTABSIZE) {
+	else if (errval > (int)-FDT_ERRTABSIZE) {
 		const char *s = fdt_errtable[-errval].str;

 		if (s)
--
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