diff mbox series

util: Use %llu for printing 'long long unsigned int'

Message ID 20210724153427.574996-1-festevam@gmail.com
State Accepted
Headers show
Series util: Use %llu for printing 'long long unsigned int' | expand

Commit Message

Fabio Estevam July 24, 2021, 3:34 p.m. UTC
Use %llu for printing 'long long unsigned int' to fix the following
build warning:

In file included from core/util.c:33:
core/util.c: In function 'check_free_space':
include/util.h:91:11: warning: format '%lu' expects argument of type 'long unsigned int', but argument 9 has type '__fsblkcnt64_t' {aka 'long long unsigned int'} [-Wformat=]
   91 |           "ERROR %s : %s : %d : " format, \
      |           ^~~~~~~~~~~~~~~~~~~~~~~
include/util.h:109:2: note: in expansion of macro 'swupdate_notify'
  109 |  swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg)
      |  ^~~~~~~~~~~~~~~
core/util.c:1061:3: note: in expansion of macro 'ERROR'
 1061 |   ERROR("Not enough free space to extract %s (needed %llu, got %lu)",
 
Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 core/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Babic July 25, 2021, 10:33 a.m. UTC | #1
On 24.07.21 17:34, Fabio Estevam wrote:
> Use %llu for printing 'long long unsigned int' to fix the following
> build warning:
> 
> In file included from core/util.c:33:
> core/util.c: In function 'check_free_space':
> include/util.h:91:11: warning: format '%lu' expects argument of type 'long unsigned int', but argument 9 has type '__fsblkcnt64_t' {aka 'long long unsigned int'} [-Wformat=]
>     91 |           "ERROR %s : %s : %d : " format, \
>        |           ^~~~~~~~~~~~~~~~~~~~~~~
> include/util.h:109:2: note: in expansion of macro 'swupdate_notify'
>    109 |  swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg)
>        |  ^~~~~~~~~~~~~~~
> core/util.c:1061:3: note: in expansion of macro 'ERROR'
>   1061 |   ERROR("Not enough free space to extract %s (needed %llu, got %lu)",
>   
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>   core/util.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/core/util.c b/core/util.c
> index ebeb8587644e..d4ff9408e84f 100644
> --- a/core/util.c
> +++ b/core/util.c
> @@ -1114,7 +1114,7 @@ static bool check_free_space(int fd, long long size, char *fname)
>   	}
>   
>   	if (statvfs.f_bfree * statvfs.f_bsize < size) {
> -		ERROR("Not enough free space to extract %s (needed %llu, got %lu)",
> +		ERROR("Not enough free space to extract %s (needed %llu, got %llu)",
>   		       fname, size, statvfs.f_bfree * statvfs.f_bsize);
>   		return false;
>   	}
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
Storm, Christian July 26, 2021, 1:16 p.m. UTC | #2
Hi,

> Use %llu for printing 'long long unsigned int' to fix the following
> build warning:
> 
> In file included from core/util.c:33:
> core/util.c: In function 'check_free_space':
> include/util.h:91:11: warning: format '%lu' expects argument of type 'long unsigned int', but argument 9 has type '__fsblkcnt64_t' {aka 'long long unsigned int'} [-Wformat=]
>    91 |           "ERROR %s : %s : %d : " format, \
>       |           ^~~~~~~~~~~~~~~~~~~~~~~
> include/util.h:109:2: note: in expansion of macro 'swupdate_notify'
>   109 |  swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg)
>       |  ^~~~~~~~~~~~~~~
> core/util.c:1061:3: note: in expansion of macro 'ERROR'
>  1061 |   ERROR("Not enough free space to extract %s (needed %llu, got %lu)",
>  
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>  core/util.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/core/util.c b/core/util.c
> index ebeb8587644e..d4ff9408e84f 100644
> --- a/core/util.c
> +++ b/core/util.c
> @@ -1114,7 +1114,7 @@ static bool check_free_space(int fd, long long size, char *fname)
>  	}
>  
>  	if (statvfs.f_bfree * statvfs.f_bsize < size) {
> -		ERROR("Not enough free space to extract %s (needed %llu, got %lu)",
> +		ERROR("Not enough free space to extract %s (needed %llu, got %llu)",
>  		       fname, size, statvfs.f_bfree * statvfs.f_bsize);
>  		return false;
>  	}


With this applied, I get

In file included from core/util.c:34:
core/util.c: In function ‘check_free_space’:
include/util.h:91:41: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘long unsigned int’ [-Wformat=]
   91 |                                         "ERROR %s : %s : %d : " format, \
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~
include/util.h:109:9: note: in expansion of macro ‘swupdate_notify’
  109 |         swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg)
      |         ^~~~~~~~~~~~~~~
core/util.c:1114:17: note: in expansion of macro ‘ERROR’
 1114 |                 ERROR("Not enough free space to extract %s (needed %llu, got %llu)",
      |                 ^~~~~


So I guess we need to be more specific about the types' size used here...



Kind regards,
   Christian
Fabio Estevam July 26, 2021, 1:58 p.m. UTC | #3
Hi Christian,

On Mon, Jul 26, 2021 at 10:14 AM Christian Storm
<christian.storm@siemens.com> wrote:

> With this applied, I get
>
> In file included from core/util.c:34:
> core/util.c: In function ‘check_free_space’:
> include/util.h:91:41: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘long unsigned int’ [-Wformat=]
>    91 |                                         "ERROR %s : %s : %d : " format, \
>       |                                         ^~~~~~~~~~~~~~~~~~~~~~~
> include/util.h:109:9: note: in expansion of macro ‘swupdate_notify’
>   109 |         swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg)
>       |         ^~~~~~~~~~~~~~~
> core/util.c:1114:17: note: in expansion of macro ‘ERROR’
>  1114 |                 ERROR("Not enough free space to extract %s (needed %llu, got %llu)",
>       |                 ^~~~~
>
>
> So I guess we need to be more specific about the types' size used here...

Thanks for reporting the build warning on your system.

I think the change below against master will make the build happy
again for our systems:
https://pastebin.com/raw/bc7xpM8T

Could you please confirm?

Thanks
Storm, Christian July 26, 2021, 4:24 p.m. UTC | #4
Hi Fabio,

> > With this applied, I get
> >
> > In file included from core/util.c:34:
> > core/util.c: In function ‘check_free_space’:
> > include/util.h:91:41: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 9 has type ‘long unsigned int’ [-Wformat=]
> >    91 |                                         "ERROR %s : %s : %d : " format, \
> >       |                                         ^~~~~~~~~~~~~~~~~~~~~~~
> > include/util.h:109:9: note: in expansion of macro ‘swupdate_notify’
> >   109 |         swupdate_notify(FAILURE, format, ERRORLEVEL, ## arg)
> >       |         ^~~~~~~~~~~~~~~
> > core/util.c:1114:17: note: in expansion of macro ‘ERROR’
> >  1114 |                 ERROR("Not enough free space to extract %s (needed %llu, got %llu)",
> >       |                 ^~~~~
> >
> >
> > So I guess we need to be more specific about the types' size used here...
> 
> Thanks for reporting the build warning on your system.
> 
> I think the change below against master will make the build happy
> again for our systems:
> https://pastebin.com/raw/bc7xpM8T
> 
> Could you please confirm?

Yes, that works. I'm just wondering whether that works on all systems 
as in /usr/include/bits/statvfs.h you have a #ifndef __USE_FILE_OFFSET64
for struct statvfs...


Kind regards,
   Christian
Fabio Estevam July 26, 2021, 4:36 p.m. UTC | #5
Hi Christian,

On Mon, Jul 26, 2021 at 1:22 PM Christian Storm
<christian.storm@siemens.com> wrote:

> Yes, that works. I'm just wondering whether that works on all systems
> as in /usr/include/bits/statvfs.h you have a #ifndef __USE_FILE_OFFSET64
> for struct statvfs...

After thinking more about it, I think it would be better to still use
%llu and cast it like this instead:
https://pastebin.com/raw/MfmcWct2

Do you agree?

Thanks,

Fabio Estevam
Stefano Babic July 30, 2021, 6:04 a.m. UTC | #6
On 26.07.21 18:36, Fabio Estevam wrote:
> Hi Christian,
> 
> On Mon, Jul 26, 2021 at 1:22 PM Christian Storm
> <christian.storm@siemens.com> wrote:
> 
>> Yes, that works. I'm just wondering whether that works on all systems
>> as in /usr/include/bits/statvfs.h you have a #ifndef __USE_FILE_OFFSET64
>> for struct statvfs...
> 
> After thinking more about it, I think it would be better to still use
> %llu and cast it like this instead:
> https://pastebin.com/raw/MfmcWct2
> 
> Do you agree?
> 

Fine with me - do you send a patch ?

Regards,
Stefano
Storm, Christian July 30, 2021, 11:59 a.m. UTC | #7
> > > Yes, that works. I'm just wondering whether that works on all systems
> > > as in /usr/include/bits/statvfs.h you have a #ifndef __USE_FILE_OFFSET64
> > > for struct statvfs...
> > 
> > After thinking more about it, I think it would be better to still use
> > %llu and cast it like this instead:
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpastebin.com%2Fraw%2FMfmcWct2&amp;data=04%7C01%7Cf12e6810-e622-4957-a0c8-c67ff4e321b6%40ad011.siemens.com%7C2a67243e99d147bf681008d9531fe023%7C38ae3bcd95794fd4addab42e1495d55a%7C1%7C0%7C637632218631297901%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=YSIdmFv8RGVw%2FI9t%2FKk1j6RxDdIjBt3jeJ8%2BddVTX4I%3D&amp;reserved=0
> > 
> > Do you agree?
> > 
> 
> Fine with me - do you send a patch ?

Sorry for the delayed response, it's also fine with me. 


Kind regards,
   Christian
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index ebeb8587644e..d4ff9408e84f 100644
--- a/core/util.c
+++ b/core/util.c
@@ -1114,7 +1114,7 @@  static bool check_free_space(int fd, long long size, char *fname)
 	}
 
 	if (statvfs.f_bfree * statvfs.f_bsize < size) {
-		ERROR("Not enough free space to extract %s (needed %llu, got %lu)",
+		ERROR("Not enough free space to extract %s (needed %llu, got %llu)",
 		       fname, size, statvfs.f_bfree * statvfs.f_bsize);
 		return false;
 	}