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

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



On Mon, Nov 18, 2019 at 08:03:09AM +0100, Heinrich Schuchardt wrote:
> 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>

I'd prefer to have the cast in the definition of FDT_ERRTABSIZE.
Throughout libfdt, error values are generally treated as being (int),
so that's the likely type this value is going to be compared with
everywhere, not just here.

> ---
> 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)

-- 
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

Attachment: signature.asc
Description: PGP signature


[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