On Mon, Sep 21, 2020 at 05:52:57PM +0100, Andre Przywara wrote: > With -Wsign-compare, compilers warn about a mismatching signedness > in a comparison in fdt_create_with_flags(). > > We have just established that bufsize is not negative, so a cast to an > unsigned type is safe. > > Signed-off-by: Andre Przywara This looks correct, but I think we might be able to do it a bit more neatly by changing the type of hdrsize to signed instead. It's a small value, so we know that's a valid conversion, and that would let your two tests be merged into one here. > --- > libfdt/fdt_sw.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libfdt/fdt_sw.c b/libfdt/fdt_sw.c > index d65e9c8..8a76adf 100644 > --- a/libfdt/fdt_sw.c > +++ b/libfdt/fdt_sw.c > @@ -112,7 +112,7 @@ int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags) > sizeof(struct fdt_reserve_entry)); > void *fdt = buf; > > - if (bufsize < hdrsize) > + if (bufsize < 0 || (unsigned)bufsize < hdrsize) > return -FDT_ERR_NOSPACE; > > if (flags & ~FDT_CREATE_FLAGS_ALL) -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson