mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
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>
This commit is contained in:
parent
ecfb438c07
commit
d966f08fcd
13 changed files with 35 additions and 16 deletions
|
@ -88,7 +88,7 @@ void check_mem_rsv(void *fdt, int n, uint64_t addr, uint64_t size)
|
|||
}
|
||||
|
||||
void check_property(void *fdt, int nodeoffset, const char *name,
|
||||
int len, const void *val)
|
||||
unsigned int len, const void *val)
|
||||
{
|
||||
const struct fdt_property *prop;
|
||||
int retlen, namelen;
|
||||
|
@ -101,6 +101,9 @@ void check_property(void *fdt, int nodeoffset, const char *name,
|
|||
if (! prop)
|
||||
FAIL("Error retrieving \"%s\" pointer: %s", name,
|
||||
fdt_strerror(retlen));
|
||||
if (retlen < 0)
|
||||
FAIL("negative name length (%d) for returned property\n",
|
||||
retlen);
|
||||
|
||||
tag = fdt32_to_cpu(prop->tag);
|
||||
nameoff = fdt32_to_cpu(prop->nameoff);
|
||||
|
@ -112,13 +115,16 @@ void check_property(void *fdt, int nodeoffset, const char *name,
|
|||
propname = fdt_get_string(fdt, nameoff, &namelen);
|
||||
if (!propname)
|
||||
FAIL("Couldn't get property name: %s", fdt_strerror(namelen));
|
||||
if (namelen != strlen(propname))
|
||||
if (namelen < 0)
|
||||
FAIL("negative name length (%d) for returned string\n",
|
||||
namelen);
|
||||
if ((unsigned)namelen != strlen(propname))
|
||||
FAIL("Incorrect prop name length: %d instead of %zd",
|
||||
namelen, strlen(propname));
|
||||
if (!streq(propname, name))
|
||||
FAIL("Property name mismatch \"%s\" instead of \"%s\"",
|
||||
propname, name);
|
||||
if (proplen != retlen)
|
||||
if (proplen != (unsigned)retlen)
|
||||
FAIL("Length retrieved for \"%s\" by fdt_get_property()"
|
||||
" differs from stored length (%d != %d)",
|
||||
name, retlen, proplen);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue