From: Phillip Wood <phillip.wood123@gmail.com>
To: Elia Pinto <gitter.spiros@gmail.com>, git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
Christian Couder <christian.couder@gmail.com>
Subject: Re: [PATCH v3 2/4] diff: use size_t for the allocation size of word-diff buffers
Date: Tue, 24 Nov 2026 17:02:57 +0000 [thread overview]
Message-ID: <9ff62027-f0a1-478f-b038-9ece951e6c17@gmail.com> (raw)
In-Reply-To: <b27ef2a8882c2badb88d257ca28ed38b67c13c1b.1793439137.git.gitter.spiros@gmail.com>
Hi Elia
On 31/10/2026 10:16, Elia Pinto wrote:
>
> @@ -2192,7 +2192,7 @@ static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out,
> regex_t *word_regex)
> {
> int i, j;
I've added more context below where you can see that i and j are used as
offsets into buffer->text, so if we are making alloc a size_t, don't we
need to do the same for those and also buffer->orig_{nr,alloc}? There is
a complication though, i and j end up being converted regoff_t which is
"a signed integer type capable of storing the largest value that can be
stored in either an ptrdiff_t type or a ssize_t type". I think that
means they're likely to be bounded to INT_MAX on 32bit platforms which
makes supporting buffers larger than 2GB on those platforms tricky.
Thanks
Phillip
> - long alloc = 0;
> + size_t alloc = 0;
>
> out->size = 0;
> out->ptr = NULL;
/* fake an empty "0th" word */
ALLOC_GROW(buffer->orig, 1, buffer->orig_alloc);
buffer->orig[0].begin = buffer->orig[0].end = buffer->text.ptr;
buffer->orig_nr = 1;
for (i = 0; i < buffer->text.size; i++) {
if (find_word_boundaries(&buffer->text, word_regex, &i, &j))
return;
/* store original boundaries */
ALLOC_GROW(buffer->orig, buffer->orig_nr + 1,
buffer->orig_alloc);
buffer->orig[buffer->orig_nr].begin = buffer->text.ptr + i;
buffer->orig[buffer->orig_nr].end = buffer->text.ptr + j;
buffer->orig_nr++;
/* store one word */
ALLOC_GROW(out->ptr, out->size + j - i + 1, alloc);
memcpy(out->ptr + out->size, buffer->text.ptr + i, j - i);
out->ptr[out->size + j - i] = '\n';
out->size += j - i + 1;
i = j - 1;
}
}
next prev parent reply other threads:[~2026-11-24 17:02 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 10:16 [PATCH 0/3] use size_t for a few more object and buffer sizes Elia Pinto
2026-10-21 10:16 ` [PATCH 1/3] odb: use size_t for the length of objects to write Elia Pinto
2026-10-21 11:24 ` Patrick Steinhardt
2026-10-21 10:16 ` [PATCH 2/3] diff: use size_t for the allocation size of word-diff buffers Elia Pinto
2026-10-21 11:24 ` Patrick Steinhardt
2026-10-21 10:16 ` [PATCH 3/3] convert: use size_t for buffer sizes Elia Pinto
2026-10-21 11:24 ` Patrick Steinhardt
2026-10-30 9:58 ` [PATCH v2 0/4] use size_t for a few more object and " Elia Pinto
2026-10-30 9:58 ` [PATCH v2 1/4] odb: use size_t for the length of objects to write Elia Pinto
2026-10-30 11:44 ` Patrick Steinhardt
2026-10-31 10:16 ` Elia Pinto
2026-10-30 9:58 ` [PATCH v2 2/4] diff: use size_t for the allocation size of word-diff buffers Elia Pinto
2026-10-30 9:58 ` [PATCH v2 3/4] convert: use size_t for buffer sizes Elia Pinto
2026-10-30 9:58 ` [PATCH v2 4/4] convert: use size_t for text statistics and ident counts Elia Pinto
2026-10-30 11:44 ` Patrick Steinhardt
2026-10-31 10:16 ` Elia Pinto
2026-11-02 11:09 ` Patrick Steinhardt
2026-11-02 20:16 ` Junio C Hamano
2026-11-03 6:59 ` Patrick Steinhardt
2026-10-31 10:16 ` [PATCH v3 0/4] use size_t for a few more object and buffer sizes Elia Pinto
2026-10-31 10:16 ` [PATCH v3 1/4] odb: use size_t for the length of objects to write Elia Pinto
2026-11-23 11:39 ` Christian Couder
2026-10-31 10:16 ` [PATCH v3 2/4] diff: use size_t for the allocation size of word-diff buffers Elia Pinto
2026-11-23 11:40 ` Christian Couder
2026-11-24 17:02 ` Phillip Wood [this message]
2026-10-31 10:16 ` [PATCH v3 3/4] convert: use size_t for buffer sizes Elia Pinto
2026-11-23 11:40 ` Christian Couder
2026-11-25 13:24 ` Toon Claes
2026-11-25 17:39 ` Junio C Hamano
2026-10-31 10:16 ` [PATCH v3 4/4] convert: use size_t for text statistics and ident counts Elia Pinto
2026-11-23 11:41 ` Christian Couder
2026-11-19 7:12 ` [PATCH v3 0/4] use size_t for a few more object and buffer sizes Elia Pinto
2026-11-23 11:48 ` Christian Couder
2026-11-23 19:34 ` Junio C Hamano
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=9ff62027-f0a1-478f-b038-9ece951e6c17@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=gitter.spiros@gmail.com \
--cc=peff@peff.net \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox