* [PATCH 1/1] mkimage: struct stat.st_size may not be long
@ 2022-01-15 19:12 Heinrich Schuchardt
2022-01-17 20:20 ` Milan P. Stanić
2022-01-24 16:53 ` Tom Rini
0 siblings, 2 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2022-01-15 19:12 UTC (permalink / raw)
To: Tom Rini
Cc: Simon Glass, Alexandru Gagniuc, Thomas Hebb, Yann Dirson,
Joel Stanley, u-boot, Heinrich Schuchardt, Milan P . Stanić
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ć <mps@arvanta.net>
Fixes: 331f0800f1a3 ("mkimage: allow -l to work on block devices on Linux")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] mkimage: struct stat.st_size may not be long
2022-01-15 19:12 [PATCH 1/1] mkimage: struct stat.st_size may not be long Heinrich Schuchardt
@ 2022-01-17 20:20 ` Milan P. Stanić
2022-01-17 20:35 ` Mark Kettenis
2022-01-24 16:53 ` Tom Rini
1 sibling, 1 reply; 4+ messages in thread
From: Milan P. Stanić @ 2022-01-17 20:20 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: Tom Rini, Simon Glass, Alexandru Gagniuc, Thomas Hebb,
Yann Dirson, Joel Stanley, u-boot
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ć <mps@arvanta.net>
> Fixes: 331f0800f1a3 ("mkimage: allow -l to work on block devices on Linux")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Tested by: Milan P. Stanić <mps@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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] mkimage: struct stat.st_size may not be long
2022-01-17 20:20 ` Milan P. Stanić
@ 2022-01-17 20:35 ` Mark Kettenis
0 siblings, 0 replies; 4+ messages in thread
From: Mark Kettenis @ 2022-01-17 20:35 UTC (permalink / raw)
To: Milan P. Stanić
Cc: heinrich.schuchardt, trini, sjg, mr.nuke.me, tommyhebb, yann,
joel, u-boot
> Date: Mon, 17 Jan 2022 21:20:58 +0100
> From: Milan P. Stanić <mps@arvanta.net>
>
> 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ć <mps@arvanta.net>
> > Fixes: 331f0800f1a3 ("mkimage: allow -l to work on block devices on Linux")
> > Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
>
> Tested by: Milan P. Stanić <mps@arvanta.net>
This will also fix a warning on OpenBSD. So:
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
> > ---
> > 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
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] mkimage: struct stat.st_size may not be long
2022-01-15 19:12 [PATCH 1/1] mkimage: struct stat.st_size may not be long Heinrich Schuchardt
2022-01-17 20:20 ` Milan P. Stanić
@ 2022-01-24 16:53 ` Tom Rini
1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2022-01-24 16:53 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: Simon Glass, Alexandru Gagniuc, Thomas Hebb, Yann Dirson,
Joel Stanley, u-boot, Milan P . Stanić
[-- Attachment #1: Type: text/plain, Size: 1146 bytes --]
On Sat, Jan 15, 2022 at 08:12:56PM +0100, 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ć <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>
Applied to u-boot/master, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-01-24 16:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-15 19:12 [PATCH 1/1] mkimage: struct stat.st_size may not be long Heinrich Schuchardt
2022-01-17 20:20 ` Milan P. Stanić
2022-01-17 20:35 ` Mark Kettenis
2022-01-24 16:53 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox