It fixes these warnings below.

On Sat, 2022-01-15 at 20:12, Heinrich Schuchardt wrote:
> The component st_size of struct stat is of type off_t. Depending on the
> system printing it it with %ld leads to a warning:
> 
> tools/mkimage.c:438:54: warning: format '%ld' expects argument of type
> 'long int', but argument 5 has type
> 'off_t' {aka 'long long int'} [-Wformat=]
>   438 |     "%s: Bad size: \"%s\" is not valid image: size %ld < %u\n",
>       |                                                    ~~^
>       |                                                      |
>       |                                                      long int
>       |                                                    %lld
> 
> When comparing an off_t value to a 32bit integer we should not convert to
> uint32_t but to off_t which may be wider.
> 
> Reported-by: Milan P. Stanić <m...@arvanta.net>
> Fixes: 331f0800f1a3 ("mkimage: allow -l to work on block devices on Linux")
> Signed-off-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com>

Tested by: Milan P. Stanić <m...@arvanta.net>

> ---
>  tools/mkimage.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/mkimage.c b/tools/mkimage.c
> index fbe883ce36..79042be828 100644
> --- a/tools/mkimage.c
> +++ b/tools/mkimage.c
> @@ -433,11 +433,12 @@ int main(int argc, char **argv)
>                               params.cmdname, params.imagefile);
>                       exit (EXIT_FAILURE);
>  #endif
> -             } else if ((unsigned)sbuf.st_size < tparams->header_size) {
> +             } else if (sbuf.st_size < (off_t)tparams->header_size) {
>                       fprintf (stderr,
> -                             "%s: Bad size: \"%s\" is not valid image: size 
> %ld < %u\n",
> +                             "%s: Bad size: \"%s\" is not valid image: size 
> %llu < %u\n",
>                               params.cmdname, params.imagefile,
> -                             sbuf.st_size, tparams->header_size);
> +                             (unsigned long long) sbuf.st_size,
> +                             tparams->header_size);
>                       exit (EXIT_FAILURE);
>               } else {
>                       size = sbuf.st_size;
> -- 
> 2.33.1
> 

Reply via email to