git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] midx.c: fix an integer overflow

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 28, 2020, 20:39 UTC
Message-ID
<xmqqzhd2cup5.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20200228185525.GB1408759@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 15 quoted lines
>> -	for (i = 0; i < m->num_objects - 1; i++) {
>> +	for (i = 0; i + 1 < m->num_objects; i++) {
>>  		struct object_id oid1, oid2;
>>  
>>  		nth_midxed_object_oid(&oid1, m, i);
> [...]           nth_midxed_object_oid(&oid2, m, i + 1);
>
> Perhaps it would be simpler as:
>
>   for (i = 1; i < m->num_objects; i++) {
>           ...
> 	  nth_midxed_object_oid(&oid1, m, i - 1);
> 	  nth_midxed_object_oid(&oid2, m, i);
> 	  ...
>   }

"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.
> 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 ;-)
Previous: Jeff KingNext: Damien Robert
Message 3 of 17 in “midx.c: fix an integer overflow”
  1. 1/1 midx.c: fix an integer overflowDamien Robert, Feb 28, 2020
  2. Jeff KingFeb 28, 2020
  3. Junio C HamanoFeb 28, 2020
  4. Damien RobertFeb 29, 2020
  5. Damien RobertFeb 29, 2020
  6. 1/1 midx.c: fix an integer overflowDamien Robert, Mar 12, 2020
  7. Damien RobertMar 12, 2020
  8. Derrick StoleeMar 12, 2020
  9. Damien RobertMar 12, 2020
  10. 1/1 midx.c: fix an integer overflowDamien Robert, Mar 23, 2020
  11. Jeff KingMar 24, 2020
  12. Junio C HamanoMar 24, 2020
  13. 1/1 midx.c: fix an integer overflowDamien Robert, Mar 26, 2020
  14. Junio C HamanoMar 26, 2020
  15. Damien RobertMar 28, 2020
  16. Junio C HamanoMar 28, 2020
  17. 1/1 midx.c: fix an integer underflowDamien Robert, Mar 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.