Re: [RFC PATCH 1/1] json-writer: incorrect format specifier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 24/03/18 15:14, Ramsay Jones wrote:
> 
> 
> On 24/03/18 05:37, Wink Saville wrote:
>> In routines jw_object_uint64 and jw_object_double strbuf_addf is
>> invoked with strbuf_addf(&jw->json, ":%"PRIuMAX, value) where value
>> is a uint64_t. This causes a compile error on OSX.
>>
>> The correct format specifier is PRIu64 instead of PRIuMax.
>>
>> Signed-off-by: Wink Saville <wink@xxxxxxxxxxx>
>> ---
>>  json-writer.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/json-writer.c b/json-writer.c
>> index 89a6abb57..04045448a 100644
>> --- a/json-writer.c
>> +++ b/json-writer.c
>> @@ -120,7 +120,7 @@ void jw_object_uint64(struct json_writer *jw, const char *key, uint64_t value)
>>  	maybe_add_comma(jw);
>>  
>>  	append_quoted_string(&jw->json, key);
>> -	strbuf_addf(&jw->json, ":%"PRIuMAX, value);
>> +	strbuf_addf(&jw->json, ":%"PRIu64, value);
> 
> In this code-base, that would normally be written as:
> 
> 	strbuf_addf(&jw->json, ":%"PRIuMAX, (uintmax_t) value);

heh, I should learn not to reply in a hurry, just before
going out ...

I had not noticed that 'value' was declared with an 'sized type'
of uint64_t, so using PRIu64 should be fine. Well, except that
you may have to add a 'fallback' definition of PRIu64 to one of
the 'compat/mingw.h', 'compat/msvc.h' or 'git-compat-util.h'
header files. (see e.g. PRId64 at compat/mingw.h:429).

[About a decade ago, I heard microsoft were implementing C99
'real soon now' ;-) ]

ATB,
Ramsay Jones





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux