From: Danh Doan <congdanhqx@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Elia Pinto <gitter.spiros@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH 31/32] commit-graph.c: fix code that could convert the result of an integer multiplication to a larger type
Date: Thu, 7 Nov 2019 11:06:05 +0700 [thread overview]
Message-ID: <20191107040605.GA8096@danh.dev> (raw)
In-Reply-To: <xmqqtv7gs6g3.fsf@gitster-ct.c.googlers.com>
On 2019-11-07 12:37:00 +0900, Junio C Hamano wrote:
> Danh Doan <congdanhqx@gmail.com> writes:
>
> > On 2019-11-06 11:23:00 +0900, Junio C Hamano wrote:
> >> > @@ -1454,7 +1454,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
> >> > num_chunks);
> >> > ctx->progress = start_delayed_progress(
> >> > progress_title.buf,
> >> > - num_chunks * ctx->commits.nr);
> >> > + (uint64_t)num_chunks * ctx->commits.nr);
> >>
> >> Hmph, do we need this? I understand that the second parameter to
> >> the callee is u64, so the caller needs to come up with u64 without
> >> overflow, but doesn't that automatically get promoted?
> >
> > Neither num_chunks nor ctx->commits.nr is promoted because both of
> > them are int. The result of `num_chunks * ctx->commits.nr' will be int
> > and will be promoted to u64 to pass to caller.
>
> Ah, yes. Thanks.
>
> The commit title is about "integer multiplication", but can the same
> issue arise with addition and subtraction as well, by the way?
Yes, the same issue will arise with all binary (and ternary) arithmetic operators
(+, -, *, /, %, ^, &, |, <<, >> and ?:).
IIRC, gcc doesn't have any warning for this kind of issue.
Microsoft Visual Studio (2017+) has C26451 for this.
https://docs.microsoft.com/en-us/visualstudio/code-quality/c26451?view=vs-2017
If our friends at Microsoft could help, we can check the remaining one
in our codebase.
--
Danh
next prev parent reply other threads:[~2019-11-07 4:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 9:59 [PATCH 30/32] ident.c: fix LGTM warning on the possible abuse of the '=' operator Elia Pinto
2019-11-04 9:59 ` [PATCH 31/32] commit-graph.c: fix code that could convert the result of an integer multiplication to a larger type Elia Pinto
2019-11-06 2:23 ` Junio C Hamano
2019-11-07 2:23 ` Danh Doan
2019-11-07 3:37 ` Junio C Hamano
2019-11-07 4:06 ` Danh Doan [this message]
2019-11-07 12:49 ` Johannes Schindelin
2019-11-07 12:45 ` Johannes Schindelin
2019-11-04 9:59 ` [PATCH 32/32] date.c: fix code that may overflow 'int' before it is converted to 'time_t' Elia Pinto
2019-11-04 10:26 ` [PATCH 30/32] ident.c: fix LGTM warning on the possible abuse of the '=' operator SZEDER Gábor
2019-11-04 13:55 ` Elia Pinto
2019-11-04 15:11 ` Phillip Wood
2019-11-04 19:55 ` Elia Pinto
2019-11-06 2:16 ` Junio C Hamano
2019-11-06 11:32 ` 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=20191107040605.GA8096@danh.dev \
--to=congdanhqx@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=gitter.spiros@gmail.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 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 NNTP newsgroup(s).