mkimage: struct stat.st_size may not be long 51/276551/1
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 15 Jan 2022 19:12:56 +0000 (20:12 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 20 Jun 2022 09:33:22 +0000 (18:33 +0900)
commit50f3a982c54c9f96230fae8b4ffeb940e41c3ec9
tree6568ce1274c53ea9e0e012649058fade623006fd
parent2b598c2929b4b2549c3cfab590ae4ee5d89aeead
mkimage: struct stat.st_size may not be long

The component st_size of struct stat is of type off_t. Depending on the
system printing it using %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ć <mps@arvanta.net>
Fixes: 331f0800f1a3 ("mkimage: allow -l to work on block devices on Linux")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
[jh80.chung: cherry picked from mainline commit c28f2499952a78609e80d3b1f7aca9b0aab8d6d6]

Change-Id: I533f5bfde2fd49145625b1b2dfe413111f90ef36
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
tools/mkimage.c