git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 26, 2018, 17:04 UTC
Message-ID
<xmqqr2o6dayt.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<c8628770-71d7-42f4-4bc5-444ea0160d26@ramsayjones.plus.com>
Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
Show 16 quoted lines
>>> @@ -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.

But why is this codepath using a sized type in the first place? It is not like it wants to read/write a fixed binary file format---it just wants to use an integer type that is wide enough to handle any inttype the platform uses, for which uintmax_t would be a more appropriate type, no?

Previous: Ramsay JonesNext: Jeff Hostetler
Message 6 of 12 in “json-writer: incorrect format specifier”
  1. 0/1 json-writer: incorrect format specifierWink Saville, Mar 24, 2018
  2. 1/1 json-writer: incorrect format specifierWink Saville, Mar 24, 2018
  3. Jeff HostetlerMar 24, 2018
  4. Ramsay JonesMar 24, 2018
  5. Ramsay JonesMar 24, 2018
  6. Junio C HamanoMar 26, 2018
  7. Jeff HostetlerMar 26, 2018
  8. Ramsay JonesMar 27, 2018
  9. Jeff HostetlerMar 27, 2018
  10. 0/1 json-writer: add cast to uintmax_tWink Saville, Mar 24, 2018
  11. 1/1 json-writer: add cast to uintmax_tWink Saville, Mar 24, 2018
  12. Jeff HostetlerMar 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.