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

Re: [PATCH] Make fread/fwrite-like functions in http.c more like fread/fwrite.

From
Jeff King <peff@peff.net>
Date
May 1, 2019, 18:44 UTC
Message-ID
<20190501184403.GG4109@sigill.intra.peff.net>
In-Reply-To
<20190501085635.7125-1-mh@glandium.org>
On Wed, May 01, 2019 at 05:56:35PM +0900, Mike Hommey wrote:
Show 6 quoted lines
> The fread/fwrite-like functions in http.c, namely fread_buffer,
> fwrite_buffer, fwrite_null, fwrite_sha1_file all return the
> multiplication of the size and number of items they are being given.
> 
> Practically speaking, it doesn't matter, because in all contexts where
> those functions are used, size is 1.
Wow, this is a long-standing bug. :)

I think it's further confused by curl's documentation. E.g., CURLOPT_WRITEFUNCTION says:

  Your callback should return the number of bytes actually taken care of.

To me, "number of bytes" implies implies size * nmemb. But earlier it says:

  ptr points to the delivered data, and the size of that data is nmemb;
  size is always 1.

So I think they just use "nmemb" and "bytes" interchangeably. Which is correct, but misleading if you didn't read the whole thing.

At any rate, I think your patch is worth applying. It should have no impact when used with curl, and is one less gotcha for somebody trying to use these elsewhere.

Another option would be to actually assert(eltsize == 1), and then just use nmemb consistently. That might make the logic a little easier to follow, but I doubt it matters much either way.

-Peff
Previous: Mike HommeyNext: SZEDER Gábor
Message 2 of 5 in “Make fread/fwrite-like functions in http.c more like fread/fwrite.”
  1. Make fread/fwrite-like functions in http.c more like fread/fwrite.Mike Hommey, May 1, 2019
  2. Jeff KingMay 1, 2019
  3. SZEDER GáborMay 7, 2019
  4. Jeff KingMay 7, 2019
  5. Make fread/fwrite-like functions in http.c more like fread/fwrite.Mike Hommey, May 7, 2019

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.