From: Damien Robert <damien.olivier.robert@gmail.com> To: Junio C Hamano <gitster@pobox.com> Cc: Jeff King <peff@peff.net>, git@vger.kernel.org, Derrick Stolee <dstolee@microsoft.com>, William Baker <William.Baker@microsoft.com> Subject: Re: [PATCH 1/1] midx.c: fix an integer overflow Date: Sat, 29 Feb 2020 18:15:40 +0100 Message-ID: <20200229154241.gxwb4u7l5u6iaveg@doriath> (raw) In-Reply-To: <xmqqzhd2cup5.fsf@gitster-ct.c.googlers.com> From Junio C Hamano, Fri 28 Feb 2020 at 12:39:50 (-0800) : > "Count up while i+1 is smaller than..." looked extremely unnatural and > it was hard to grok, at least to me. This > for (i = 0; i < m->num_objects - 1; i++) { > > might have been more palatable, but yours is much better. This is probably a question of taste. The for (i = 0; i < m->num_objects - 1; i++) { looks like someone who forgot to use <= instead of < to me (until the body of the for explain that we are actually iterating over two consecutive objects), while for (i = 0; i + 1 < m->num_objects; i++) { makes it clear that we are iterating over two objects (and has the advantage of not overflowing :)) > > Though I almost wonder if we should be catching "m->num_objects == 0" > > early and declaring the midx to be bogus (it's not _technically_ wrong, > > but I'd have to suspect a bug in anything that generated a 0-object midx > > file). > That, too ;-) Yeah I'll go for that solution in my reroll. -- Damien Robert http://www.normalesup.org/~robert/pro
next prev parent reply other threads:[~2020-02-29 17:15 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-02-28 16:24 Damien Robert 2020-02-28 18:55 ` Jeff King 2020-02-28 20:39 ` Junio C Hamano 2020-02-29 17:15 ` Damien Robert [this message] 2020-02-29 15:38 ` Damien Robert 2020-03-12 17:35 ` [PATCH v2 " Damien Robert 2020-03-12 18:24 ` Damien Robert 2020-03-12 18:28 ` Derrick Stolee 2020-03-12 21:41 ` Damien Robert 2020-03-23 22:25 ` [PATCH v3 " Damien Robert 2020-03-24 6:01 ` Jeff King 2020-03-24 18:48 ` Junio C Hamano 2020-03-26 21:35 ` [PATCH v4 " Damien Robert 2020-03-26 23:27 ` Junio C Hamano 2020-03-28 22:23 ` Damien Robert 2020-03-28 23:51 ` Junio C Hamano 2020-03-28 22:18 ` [PATCH 1/1] midx.c: fix an integer underflow Damien Robert
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 List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200229154241.gxwb4u7l5u6iaveg@doriath \ --to=damien.olivier.robert@gmail.com \ --cc=William.Baker@microsoft.com \ --cc=dstolee@microsoft.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=peff@peff.net \ /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
git@vger.kernel.org list mirror (unofficial, one of many) This inbox may be cloned and mirrored by anyone: git clone --mirror http://public-inbox.org/git git clone --mirror http://ou63pmih66umazou.onion/git git clone --mirror http://czquwvybam4bgbro.onion/git git clone --mirror http://hjrcffqmbrq6wope.onion/git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 git git/ http://public-inbox.org/git \ git@vger.kernel.org public-inbox-index git Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.version-control.git nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git nntp://news.gmane.io/gmane.comp.version-control.git note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: https://80x24.org/mirrors/git.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git