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

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

 



On Wed, May 01, 2019 at 05:56:35PM +0900, Mike Hommey wrote:

> 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



[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