summaryrefslogtreecommitdiff
path: root/libfdt/fdt_ro.c
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2020-10-01 17:46:29 +0100
committerDavid Gibson <david@gibson.dropbear.id.au>2020-10-02 10:33:01 +1000
commit6c2be7d85315008be974984c0c86a8c8e55adeea (patch)
treee111f609f0956e4e4876b0f23dd5d118079e397b /libfdt/fdt_ro.c
parent82525f41d59ec57a4e9325796a6f1baefc036236 (diff)
downloaddevice-tree-compiler-6c2be7d85315008be974984c0c86a8c8e55adeea.tar.gz
libfdt: fdt_get_string(): Fix sequential write comparison warnings
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in fdt_get_string(). Introduce a new usigned variable, which holds the actual (negated) stroffset value, so we avoid negating all the other variables and have proper types everywhere. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-6-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt/fdt_ro.c')
-rw-r--r--libfdt/fdt_ro.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index e192184..91cc6fe 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -67,11 +67,13 @@ const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
len = fdt_size_dt_strings(fdt) - stroffset;
}
} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
- if ((stroffset >= 0)
- || (stroffset < -fdt_size_dt_strings(fdt)))
+ unsigned int sw_stroffset = -stroffset;
+
+ if ((stroffset >= 0) ||
+ (sw_stroffset > fdt_size_dt_strings(fdt)))
goto fail;
- if ((-stroffset) < len)
- len = -stroffset;
+ if (sw_stroffset < len)
+ len = sw_stroffset;
} else {
err = -FDT_ERR_INTERNAL;
goto fail;