From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: git@vger.kernel.org, Ramsay Jones <ramsay@ramsayjones.plus.com>
Subject: Re: [PATCH] xsize_t: avoid implementation defined behavior when len < 0
Date: Wed, 19 May 2021 10:36:22 +0900 [thread overview]
Message-ID: <xmqqy2cbzeqx.fsf@gitster.g> (raw)
In-Reply-To: <YKPXVMchtGbwDuue@google.com> (Jonathan Nieder's message of "Tue, 18 May 2021 08:03:48 -0700")
Jonathan Nieder <jrnieder@gmail.com> writes:
> Hi,
>
> This is *not* -rc material; it's just something I noticed and figured
> I would send it before I forget (among other benefits, this helps us
> kick the tires on the release candidate by having patches to work
> with).
>
> Thoughts welcome, as always.
>
> Jonathan
>
> git-compat-util.h | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index a508dbe5a3..20318a0aac 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -986,11 +986,9 @@ static inline char *xstrdup_or_null(const char *str)
>
> static inline size_t xsize_t(off_t len)
> {
> - size_t size = (size_t) len;
> -
> - if (len != (off_t) size)
> + if (len < 0 || len > SIZE_MAX)
> die("Cannot handle files this big");
OK, so negative offset or offset that cannot be represented as size_t
are rejected. That is much easier to read than the original ;-)
SIZE_MAX is associated with size_t so it presumably is an unsigned
constant; would it again trigger a sign-compare warning?
> - return size;
> + return (size_t) len;
> }
>
> __attribute__((format (printf, 3, 4)))
next prev parent reply other threads:[~2021-05-19 1:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 15:03 [PATCH] xsize_t: avoid implementation defined behavior when len < 0 Jonathan Nieder
2021-05-19 1:36 ` Junio C Hamano [this message]
2021-05-19 1:52 ` [PATCH v2] " Jonathan Nieder
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=xmqqy2cbzeqx.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=ramsay@ramsayjones.plus.com \
/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.