git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Mike Hommey <mh@glandium.org>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH] Make fread/fwrite-like functions in http.c more like fread/fwrite.
Date: Wed, 1 May 2019 14:44:03 -0400	[thread overview]
Message-ID: <20190501184403.GG4109@sigill.intra.peff.net> (raw)
In-Reply-To: <20190501085635.7125-1-mh@glandium.org>

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

  reply	other threads:[~2019-05-01 18:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-01  8:56 [PATCH] Make fread/fwrite-like functions in http.c more like fread/fwrite Mike Hommey
2019-05-01 18:44 ` Jeff King [this message]
2019-05-07 14:58 ` SZEDER Gábor
2019-05-07 21:46   ` Jeff King
2019-05-07 23:03     ` [PATCH v2] " Mike Hommey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190501184403.GG4109@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mh@glandium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).