From: Junio C Hamano <gitster@pobox.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Alexander Meshcheryakov" <alexander.s.m@gmail.com>,
"Torsten Bögershausen" <tboegi@web.de>,
"Elijah Newren" <newren@gmail.com>
Subject: Re: [PATCH v2 4/4] diff: use uintmax_t for diffstat totals and graph scaling
Date: Tue, 17 Nov 2026 15:13:46 -0800 [thread overview]
Message-ID: <xmqqcxs3aw5x.fsf@gitster.g> (raw)
In-Reply-To: <692c503e97d9841def6e0429ef52a963ab93eec0.1794909894.git.gitter.spiros@gmail.com> (Elia Pinto's message of "Tue, 17 Nov 2026 11:37:56 +0100")
Elia Pinto <gitter.spiros@gmail.com> writes:
> struct diffstat_file stores the number of added and deleted lines of
> each file in uintmax_t, but show_stats() and show_shortstats() add them
> up in "int" variables. When the total goes over INT_MAX, the summary
> line overflows. With the previous patch, a single file is enough: for
> a complete rewrite into a file of 2^31 lines, "git diff -B --stat"
> ends with
>
> 1 file changed, -2147483648 insertions(+), 1000 deletions(-)
>
> Several files whose changes add up to more than INT_MAX lines lead to
> the same overflow even without -B.
>
> Use uintmax_t for these totals and for the parameters of
> print_stat_summary() and print_stat_summary_inserts_deletes(), which
> printed them with "%d". print_stat_summary() is also called by
> "git apply --stat", hence the change of its prototype in diff.h.
> apply.c still adds up its own totals in "int"; it is left alone here.
The above is super detailed write up but still leaves readers
confused because a crucial question is left unanswered.
So we use a wider type to accumulate changes to avoid overflowing
the accumulator of a narrower type. But then what else is done to
deal with the accumulator of the winder type that overflows after
enough numbers are added to it?
The remainder of the proposed log message shares exactly the same
issue. It points out different areas that use narrow accumulator
causing trouble by overflowing, talks about replacing them with
accumulator of wider type, but stops there without answering the
same crucial question.
> - graph_width = max_change + 4 > bin_width ? max_change : bin_width - 4;
> + if (max_change + 4 > bin_width)
> + /* anything wider than "width" is cut down below anyway */
> + graph_width = max_change < width ? max_change : width;
> + else
> + graph_width = bin_width - 4;
This change looks more interesting than a mere type widening, but I
do not think we saw it described in the proposed log message that
was a wall of text.
prev parent reply other threads:[~2026-11-17 23:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 15:36 [PATCH 0/3] use size_t for a few sizes that are 32 bits everywhere Elia Pinto
2026-11-01 15:36 ` [PATCH 1/3] csum-file: use size_t for the count passed to hashwrite() Elia Pinto
2026-11-01 15:36 ` [PATCH 2/3] diff: use size_t for the size passed to count_lines() Elia Pinto
2026-11-04 13:58 ` Phillip Wood
2026-11-04 15:45 ` Phillip Wood
2026-11-01 15:36 ` [PATCH 3/3] diffcore-delta: use size_t for the size of the buffer to hash Elia Pinto
2026-11-17 10:37 ` [PATCH v2 0/4] widen a few sizes and counts that are 32 bits everywhere Elia Pinto
2026-11-17 10:37 ` [PATCH v2 1/4] csum-file: use size_t for the count passed to hashwrite() Elia Pinto
2026-11-17 17:52 ` Junio C Hamano
2026-11-17 23:50 ` brian m. carlson
2026-11-17 10:37 ` [PATCH v2 2/4] diff: use size_t for sizes and line counts of complete rewrites Elia Pinto
2026-11-17 10:37 ` [PATCH v2 3/4] diffcore-delta: use size_t for the size of the buffer to hash Elia Pinto
2026-11-17 23:21 ` Junio C Hamano
2026-11-17 10:37 ` [PATCH v2 4/4] diff: use uintmax_t for diffstat totals and graph scaling Elia Pinto
2026-11-17 16:36 ` Torsten Bögershausen
2026-11-17 23:13 ` Junio C Hamano [this message]
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=xmqqcxs3aw5x.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=alexander.s.m@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitter.spiros@gmail.com \
--cc=newren@gmail.com \
--cc=tboegi@web.de \
/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.