All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Martin Koegler <martin.koegler@chello.at>
Cc: git@vger.kernel.org, Johannes.Schindelin@gmx.de
Subject: Re: [PATCH] Convert size datatype to size_t
Date: Tue, 08 Aug 2017 14:46:40 -0700	[thread overview]
Message-ID: <xmqqmv79ag1r.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1502222450-20815-1-git-send-email-martin@mail.zuhause> (Martin Koegler's message of "Tue, 8 Aug 2017 22:00:50 +0200")

Martin Koegler <martin.koegler@chello.at> writes:

> diff --git a/apply.c b/apply.c
> index f2d5991..ea97fd2 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -3085,7 +3085,7 @@ static int apply_binary_fragment(struct apply_state *state,
>  				 struct patch *patch)
>  {
>  	struct fragment *fragment = patch->fragments;
> -	unsigned long len;
> +	size_t len;
>  	void *dst;
>  
>  	if (!fragment)

This variable is made size_t because it receives the result size of
patch_delta().  And it later is assigned to img->len field, which
already is size_t before this patch.

Curiously, the patch_delta() invocation with this patch reads like
this:

		dst = patch_delta(img->buf, img->len, fragment->patch,
				  fragment->size, &len);

where patch_delta() is updated (correctly) to:

    void *patch_delta(const void *src_buf, size_t src_size,
                      const void *delta_buf, size_t delta_size,
                      size_t *dst_size)

with this patch.  But "size" field in "struct fragment" is still
"int".  So we'd need to update it as well, not necessarily in this
patch (which is already too big) but as part of a larger whole.

> @@ -3174,7 +3174,7 @@ static int apply_binary(struct apply_state *state,
>  	if (has_sha1_file(oid.hash)) {
>  		/* We already have the postimage */
>  		enum object_type type;
> -		unsigned long size;
> +		size_t size;
>  		char *result;
>  
>  		result = read_sha1_file(oid.hash, &type, &size);

This is to receive the resulting size from read_sha1_file().  It is
assigned to img->len, which is already size_t, so all is good here.

> @@ -3236,7 +3236,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
>  		strbuf_addf(buf, "Subproject commit %s\n", oid_to_hex(oid));
>  	} else {
>  		enum object_type type;
> -		unsigned long sz;
> +		size_t sz;
>  		char *result;
>  
>  		result = read_sha1_file(oid->hash, &type, &sz);

By reading the remainder of this function, this conversion also is
good.  sz that is now size_t is used as the size attached to an
existing strbuf like so:

		result = read_sha1_file(oid->hash, &type, &sz);
		if (!result)
			return -1;
		/* XXX read_sha1_file NUL-terminates */
		strbuf_attach(buf, result, sz, sz + 1);

in the part beyond the post context of this hunk.  In the longer
term, sz+1 we see here may want to become the overflow-safe variant
st_add().

As you said in the comment after three-dashes in the patch, a lot
more work is needed and your patch is a good starting point.

I am not sure if we can split the patch somehow to make it easier to
review.  The deceptively small part of your patch, i.e.

 apply.c                  |  6 +++---

needs the above analysis to see if they are correct and what more
work is necessary, and there are 65 more files with ~190 lines
changed.


  parent reply	other threads:[~2017-08-08 21:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 20:00 [PATCH] Convert size datatype to size_t Martin Koegler
2017-08-08 21:21 ` Junio C Hamano
2017-08-08 21:46 ` Junio C Hamano [this message]
2017-08-09  6:04 ` Junio C Hamano
2017-08-09  7:19   ` Martin Koegler
2017-08-09  7:26     ` Martin Koegler
2017-08-09 16:51       ` Junio C Hamano
2017-08-09 22:12         ` Johannes Schindelin
2017-08-09 22:16 ` Johannes Schindelin

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

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

  git send-email \
    --in-reply-to=xmqqmv79ag1r.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=martin.koegler@chello.at \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.