diff mbox

[kvm-unit-tests] lib: use %zu conversion for sizeof to fix i386 build

Message ID 20170512151545.13507-1-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář May 12, 2017, 3:15 p.m. UTC
Fixes this GCC error:

In file included from lib/report.c:13:0:
lib/libcflat.h:134:10: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Werror=format=]
   printf("%s:%d: assert failed: %s: " fmt "\n",  \
          ^
lib/report.c:53:2: note: in expansion of macro ‘assert_msg’
  assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
  ^~~~~~~~~~
lib/report.c:53:46: note: format string is defined here
  assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
                                            ~~^
                                            %u

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 lib/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini May 12, 2017, 3:23 p.m. UTC | #1
On 12/05/2017 17:15, Radim Krčmář wrote:
> Fixes this GCC error:
> 
> In file included from lib/report.c:13:0:
> lib/libcflat.h:134:10: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Werror=format=]
>    printf("%s:%d: assert failed: %s: " fmt "\n",  \
>           ^
> lib/report.c:53:2: note: in expansion of macro ‘assert_msg’
>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>   ^~~~~~~~~~
> lib/report.c:53:46: note: format string is defined here
>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>                                             ~~^
>                                             %u
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> ---
>  lib/report.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/report.c b/lib/report.c
> index f7af596f1fc4..b002d2107e37 100644
> --- a/lib/report.c
> +++ b/lib/report.c
> @@ -35,14 +35,14 @@ void report_prefix_pushf(const char *prefix_fmt, ...)
>  	spin_lock(&lock);
>  
>  	len = strlen(prefixes);
> -	assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
> +	assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
>  	start = len;
>  
>  	va_start(va, prefix_fmt);
>  	len += vsnprintf(&prefixes[len], sizeof(prefixes) - len, prefix_fmt,
>  			 va);
>  	va_end(va);
> -	assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
> +	assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
>  
>  	assert_msg(!strstr(&prefixes[start], PREFIX_DELIMITER),
>  		   "Prefix \"%s\" contains delimiter \"" PREFIX_DELIMITER "\"",
> @@ -50,7 +50,7 @@ void report_prefix_pushf(const char *prefix_fmt, ...)
>  
>  	len += snprintf(&prefixes[len], sizeof(prefixes) - len,
>  			PREFIX_DELIMITER);
> -	assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
> +	assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
>  
>  	spin_unlock(&lock);
>  }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Radim Krčmář May 12, 2017, 3:28 p.m. UTC | #2
2017-05-12 17:15+0200, Radim Krčmář:
> Fixes this GCC error:
> 
> In file included from lib/report.c:13:0:
> lib/libcflat.h:134:10: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Werror=format=]
>    printf("%s:%d: assert failed: %s: " fmt "\n",  \
>           ^
> lib/report.c:53:2: note: in expansion of macro ‘assert_msg’
>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>   ^~~~~~~~~~
> lib/report.c:53:46: note: format string is defined here
>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>                                             ~~^
>                                             %u
> 
> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> ---

Ugh, and I didn't test it ... libcflat doesn't support %z.
Casting the sizeof result to unsigned would work, but I don't like it
one bit.  Is there a convention in naming the conversion?  (like PRI...)

Thanks.
Paolo Bonzini May 12, 2017, 3:43 p.m. UTC | #3
On 12/05/2017 17:28, Radim Krčmář wrote:
> 2017-05-12 17:15+0200, Radim Krčmář:
>> Fixes this GCC error:
>>
>> In file included from lib/report.c:13:0:
>> lib/libcflat.h:134:10: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Werror=format=]
>>    printf("%s:%d: assert failed: %s: " fmt "\n",  \
>>           ^
>> lib/report.c:53:2: note: in expansion of macro ‘assert_msg’
>>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>>   ^~~~~~~~~~
>> lib/report.c:53:46: note: format string is defined here
>>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>>                                             ~~^
>>                                             %u
>>
>> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
>> ---
> 
> Ugh, and I didn't test it ... libcflat doesn't support %z.

Let's add it, I have sent a patch.

Paolo
Radim Krčmář May 12, 2017, 3:57 p.m. UTC | #4
2017-05-12 17:43+0200, Paolo Bonzini:
> On 12/05/2017 17:28, Radim Krčmář wrote:
> > 2017-05-12 17:15+0200, Radim Krčmář:
> >> Fixes this GCC error:
> >>
> >> In file included from lib/report.c:13:0:
> >> lib/libcflat.h:134:10: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Werror=format=]
> >>    printf("%s:%d: assert failed: %s: " fmt "\n",  \
> >>           ^
> >> lib/report.c:53:2: note: in expansion of macro ‘assert_msg’
> >>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
> >>   ^~~~~~~~~~
> >> lib/report.c:53:46: note: format string is defined here
> >>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
> >>                                             ~~^
> >>                                             %u
> >>
> >> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> >> ---
> > 
> > Ugh, and I didn't test it ... libcflat doesn't support %z.
> 
> Let's add it, I have sent a patch.

Right, shame on me for fixing it on the wrong side!
Applied after your patch,

Thanks.
Peter Feiner May 12, 2017, 4 p.m. UTC | #5
On Fri, May 12, 2017 at 8:23 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 12/05/2017 17:15, Radim Krčmář wrote:
>> Fixes this GCC error:
>>
>> In file included from lib/report.c:13:0:
>> lib/libcflat.h:134:10: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘unsigned int’ [-Werror=format=]
>>    printf("%s:%d: assert failed: %s: " fmt "\n",  \
>>           ^
>> lib/report.c:53:2: note: in expansion of macro ‘assert_msg’
>>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>>   ^~~~~~~~~~
>> lib/report.c:53:46: note: format string is defined here
>>   assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>>                                             ~~^
>>                                             %u
>>
>> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
>> ---
>>  lib/report.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/report.c b/lib/report.c
>> index f7af596f1fc4..b002d2107e37 100644
>> --- a/lib/report.c
>> +++ b/lib/report.c
>> @@ -35,14 +35,14 @@ void report_prefix_pushf(const char *prefix_fmt, ...)
>>       spin_lock(&lock);
>>
>>       len = strlen(prefixes);
>> -     assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>> +     assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
>>       start = len;
>>
>>       va_start(va, prefix_fmt);
>>       len += vsnprintf(&prefixes[len], sizeof(prefixes) - len, prefix_fmt,
>>                        va);
>>       va_end(va);
>> -     assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>> +     assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
>>
>>       assert_msg(!strstr(&prefixes[start], PREFIX_DELIMITER),
>>                  "Prefix \"%s\" contains delimiter \"" PREFIX_DELIMITER "\"",
>> @@ -50,7 +50,7 @@ void report_prefix_pushf(const char *prefix_fmt, ...)
>>
>>       len += snprintf(&prefixes[len], sizeof(prefixes) - len,
>>                       PREFIX_DELIMITER);
>> -     assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
>> +     assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
>>
>>       spin_unlock(&lock);
>>  }
>>
>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Peter Feiner <pfeiner@google.com>
diff mbox

Patch

diff --git a/lib/report.c b/lib/report.c
index f7af596f1fc4..b002d2107e37 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -35,14 +35,14 @@  void report_prefix_pushf(const char *prefix_fmt, ...)
 	spin_lock(&lock);
 
 	len = strlen(prefixes);
-	assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
+	assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
 	start = len;
 
 	va_start(va, prefix_fmt);
 	len += vsnprintf(&prefixes[len], sizeof(prefixes) - len, prefix_fmt,
 			 va);
 	va_end(va);
-	assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
+	assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
 
 	assert_msg(!strstr(&prefixes[start], PREFIX_DELIMITER),
 		   "Prefix \"%s\" contains delimiter \"" PREFIX_DELIMITER "\"",
@@ -50,7 +50,7 @@  void report_prefix_pushf(const char *prefix_fmt, ...)
 
 	len += snprintf(&prefixes[len], sizeof(prefixes) - len,
 			PREFIX_DELIMITER);
-	assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes));
+	assert_msg(len < sizeof(prefixes), "%d >= %zu", len, sizeof(prefixes));
 
 	spin_unlock(&lock);
 }