summaryrefslogtreecommitdiff
path: root/tests/get_name.c
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2021-06-18 18:20:26 +0100
committerDavid Gibson <david@gibson.dropbear.id.au>2021-06-21 15:25:44 +1000
commitd966f08fcd21ded2ed6608097e9832e9466857fd (patch)
tree66bbd1d3edcd8cfbec6e6d860b857f06ca6a344d /tests/get_name.c
parentecfb438c07fa468a129e81c7d84c7c293c7b0150 (diff)
downloaddevice-tree-compiler-d966f08fcd21ded2ed6608097e9832e9466857fd.tar.gz
tests: Fix signedness comparisons warnings
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various files in the tests/ directory. For about half of the cases we can simply change the signed variable to be of an unsigned type, because they will never need to store negative values (which is the best fix of the problem). In the remaining cases we can cast the signed variable to an unsigned type, provided we know for sure it is not negative. We see two different scenarios here: - We either just explicitly checked for this variable to be positive (if (rc < 0) FAIL();), or - We rely on a function returning only positive values in the "length" pointer if the function returned successfully: which we just checked. At two occassions we compare with a constant "-1" (even though the variable is unsigned), so we just change this to ~0U to create an unsigned comparison value. Since this is about the tests, let's also add explicit tests for those values really not being negative. This fixes "make tests" (but not "make check" yet), when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-2-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests/get_name.c')
-rw-r--r--tests/get_name.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tests/get_name.c b/tests/get_name.c
index 5a35103..d20bf30 100644
--- a/tests/get_name.c
+++ b/tests/get_name.c
@@ -34,12 +34,14 @@ static void check_name(void *fdt, const char *path)
offset, getname, len);
if (!getname)
FAIL("fdt_get_name(%d): %s", offset, fdt_strerror(len));
+ if (len < 0)
+ FAIL("negative name length (%d) for returned node name\n", len);
if (strcmp(getname, checkname) != 0)
FAIL("fdt_get_name(%s) returned \"%s\" instead of \"%s\"",
path, getname, checkname);
- if (len != strlen(getname))
+ if ((unsigned)len != strlen(getname))
FAIL("fdt_get_name(%s) returned length %d instead of %zd",
path, len, strlen(getname));