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

Re: [PATCH v3 4/6] xdiff/xdl_cleanup_records: make limits more clear

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 27, 2026, 23:01 UTC
Message-ID
<xmqqcy0oj2s1.fsf@gitster.g>
In-Reply-To
<xmqqy0jdhtd0.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 29 quoted lines
> "Ezekiel Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Ezekiel Newren <ezekielnewren@gmail.com>
>>
>> Make the handling of per-file limits and the minimal-case clearer.
>>   * Use explicit per-file limit variables (mlim1, mlim2) and initialize
>>     them.
>>   * The additional condition `!need_min` is redudant now, remove it.
>> Best viewed with --color-words.
>>
>> Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com>
>> ---
>>  xdiff/xprepare.c | 19 ++++++++++++-------
>>  1 file changed, 12 insertions(+), 7 deletions(-)
>
> t4071 and t8015 do not like this step, even though they are happy
> with 1-3/6 applied.
>
>
>> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
>> index 386668a92d..2cf1f8d1a8 100644
>> --- a/xdiff/xprepare.c
>> +++ b/xdiff/xprepare.c
>> @@ -268,7 +268,7 @@ static bool xdl_clean_mmatch(uint8_t const *action, ptrdiff_t i, ptrdiff_t s, pt
>>   * might be potentially discarded if they appear in a run of discardable.
>>   */
>>  static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
>> -	ptrdiff_t i, nm, mlim;
>> +	ptrdiff_t i, nm, mlim1, mlim2;

Ah, the problem may manifest itself in this step in the series, but the root cause might be before this step. ptrdiff_t is signed and that is the type used for mlim/mlim1/mlim2 here, and before this series these counters count in "long" that is signed.

>> +	if (need_min) {
>> +		/* i.e. infinity */
>> +		mlim1 = SIZE_MAX;
>> +		mlim2 = SIZE_MAX;

But SIZE_MAX is the maximum that a size_t (unsigned) can take. No wonder assigning it to ptrdiff_t and assuming that any other sensible ptrdiff_t value can ever reach it. Instead, this essentially assigns -1 to mlim1 and mlim2 when need_min is true.

>> +	} else {
>> +		mlim1 = XDL_MIN(xdl_bogosqrt(xdf1->nrec), XDL_MAX_EQLIMIT);
>> +		mlim2 = XDL_MIN(xdl_bogosqrt(xdf2->nrec), XDL_MAX_EQLIMIT);

This side I do not think has much to do with the breakage, but the way XDL_MIN() is implemented, it must be noted that xdl_bogosqrt() is called twice on the same value with this rewrite ...

Show 7 quoted lines
>> +	}
>> +
>>  	/*
>>  	 * Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
>>  	 */
>> -	if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf1->nrec)) > XDL_MAX_EQLIMIT)
>> -		mlim = XDL_MAX_EQLIMIT;
... as opposed to computing the value only once, in the original.
Show 5 quoted lines
>>  	for (i = xdf1->dstart; i <= xdf1->dend; i++) {
>>  		size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
>>  		rcrec = cf->rcrecs[mph1];
>>  		nm = rcrec ? rcrec->len2 : 0;
>> -		action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;

So the original said, "if nm is not zero and need_min is true, do not bother comparing nm with anything, and always use KEEP. If need_min is false, we use INVESTIGAGE only when nm is large enough, otherwise KEEP.

>> +		action1[i] = (nm == 0) ? DISCARD: nm >= mlim1 ? INVESTIGATE: KEEP;

Updated code, when nm is not zero, does something different. if need_min is true, mlim1 is set to -1 and presumably nm is a count or length that is bounded on its lower end with 0, so it is larger than mlim1 (== -1), and we always take INVESTIGATE and never kEEP.

So the rewritten code is broken when need_min is true?

I suspect the remainder of the patch is broken exactly the same way, so the remedy would be similar?

Show 13 quoted lines
>>  	}
>>  
>> -	if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf2->nrec)) > XDL_MAX_EQLIMIT)
>> -		mlim = XDL_MAX_EQLIMIT;
>>  	for (i = xdf2->dstart; i <= xdf2->dend; i++) {
>>  		size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
>>  		rcrec = cf->rcrecs[mph2];
>>  		nm = rcrec ? rcrec->len1 : 0;
>> -		action2[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
>> +		action2[i] = (nm == 0) ? DISCARD: nm >= mlim2 ? INVESTIGATE: KEEP;
>>  	}
>>  
>>  	/*
Previous: Junio C HamanoNext: Ezekiel Newren
Message 76 of 124 in “Xdiff cleanup part 3”
  1. 00/10 Xdiff cleanup part 3Ezekiel Newren via GitGitGadget, Jan 2, 2026
  2. 01/10 ivec: introduce the C side of ivecEzekiel Newren via GitGitGadget, Jan 2, 2026
  3. Junio C HamanoJan 4, 2026
  4. Ezekiel NewrenJan 17, 2026
  5. Phillip WoodJan 8, 2026
  6. Ezekiel NewrenJan 15, 2026
  7. Phillip WoodJan 16, 2026
  8. René ScharfeJan 16, 2026
  9. Phillip WoodJan 17, 2026
  10. Ezekiel NewrenJan 17, 2026
  11. René ScharfeJan 18, 2026
  12. Ezekiel NewrenJan 17, 2026
  13. Ezekiel NewrenJan 17, 2026
  14. Phillip WoodJan 17, 2026
  15. Jeff KingJan 19, 2026
  16. Ezekiel NewrenJan 19, 2026
  17. Jeff KingJan 19, 2026
  18. D. Ben KnobleJan 20, 2026
  19. Ezekiel NewrenJan 21, 2026
  20. Jeff KingJan 21, 2026
  21. Junio C HamanoJan 21, 2026
  22. Ezekiel NewrenJan 21, 2026
  23. Phillip WoodJan 20, 2026
  24. Phillip WoodJan 20, 2026
  25. Ezekiel NewrenJan 21, 2026
  26. Phillip WoodJan 28, 2026
  27. René ScharfeJan 16, 2026
  28. Ezekiel NewrenJan 17, 2026
  29. René ScharfeJan 18, 2026
  30. 02/10 xdiff: make classic diff explicit by creating xdl_do_classic_diff()Ezekiel Newren via GitGitGadget, Jan 2, 2026
  31. Phillip WoodJan 20, 2026
  32. Ezekiel NewrenJan 21, 2026
  33. 03/10 xdiff: don't waste time guessing the number of linesEzekiel Newren via GitGitGadget, Jan 2, 2026
  34. Phillip WoodJan 20, 2026
  35. Ezekiel NewrenJan 21, 2026
  36. Phillip WoodJan 22, 2026
  37. 04/10 xdiff: let patience and histogram benefit from xdl_trim_ends()Ezekiel Newren via GitGitGadget, Jan 2, 2026
  38. Phillip WoodJan 20, 2026
  39. Phillip WoodJan 21, 2026
  40. 05/10 xdiff: use xdfenv_t in xdl_trim_ends() and xdl_cleanup_records()Ezekiel Newren via GitGitGadget, Jan 2, 2026
  41. Phillip WoodJan 20, 2026
  42. 06/10 xdiff: cleanup xdl_trim_ends()Ezekiel Newren via GitGitGadget, Jan 2, 2026
  43. Phillip WoodJan 20, 2026
  44. 07/10 xdiff: replace xdfile_t.dstart with xdfenv_t.delta_startEzekiel Newren via GitGitGadget, Jan 2, 2026
  45. Phillip WoodJan 20, 2026
  46. Phillip WoodJan 28, 2026
  47. 08/10 xdiff: replace xdfile_t.dend with xdfenv_t.delta_endEzekiel Newren via GitGitGadget, Jan 2, 2026
  48. 09/10 xdiff: remove dependence on xdlclassifier from xdl_cleanup_records()Ezekiel Newren via GitGitGadget, Jan 2, 2026
  49. René ScharfeJan 16, 2026
  50. Ezekiel NewrenJan 17, 2026
  51. René ScharfeJan 18, 2026
  52. Phillip WoodJan 21, 2026
  53. 10/10 xdiff: move xdl_cleanup_records() from xprepare.c to xdiffi.cEzekiel Newren via GitGitGadget, Jan 2, 2026
  54. Phillip WoodJan 21, 2026
  55. Phillip WoodJan 28, 2026
  56. Junio C HamanoJan 4, 2026
  57. Yee Cheng ChinJan 4, 2026
  58. Phillip WoodJan 28, 2026
  59. Junio C HamanoMar 6, 2026
  60. Ezekiel NewrenMar 9, 2026
  61. Junio C HamanoMar 9, 2026
  62. 0/5 Xdiff cleanup part 3Ezekiel Newren via GitGitGadget, Mar 25, 2026
  63. 1/5 xdiff/xdl_cleanup_records: delete local recs pointerEzekiel Newren via GitGitGadget, Mar 25, 2026
  64. 2/5 xdiff/xdl_cleanup_records: make limits more clearEzekiel Newren via GitGitGadget, Mar 25, 2026
  65. 3/5 xdiff/xdl_cleanup_records: make setting action easier to followEzekiel Newren via GitGitGadget, Mar 25, 2026
  66. 4/5 xdiff/xdl_cleanup_records: simplify INVESTIGATE handling for clarityEzekiel Newren via GitGitGadget, Mar 25, 2026
  67. 5/5 xdiff/xdl_cleanup_records: use unambiguous typesEzekiel Newren via GitGitGadget, Mar 25, 2026
  68. Junio C HamanoMar 25, 2026
  69. SZEDER GáborMar 26, 2026
  70. 0/6 Xdiff cleanup part 3Ezekiel Newren via GitGitGadget, Mar 27, 2026
  71. 1/6 xdiff/xdl_cleanup_records: delete local recs pointerEzekiel Newren via GitGitGadget, Mar 27, 2026
  72. 2/6 xdiff: use unambiguous types in xdl_bogo_sqrt()Ezekiel Newren via GitGitGadget, Mar 27, 2026
  73. 3/6 xdiff/xdl_cleanup_records: use unambiguous typesEzekiel Newren via GitGitGadget, Mar 27, 2026
  74. 4/6 xdiff/xdl_cleanup_records: make limits more clearEzekiel Newren via GitGitGadget, Mar 27, 2026
  75. Junio C HamanoMar 27, 2026
  76. Junio C HamanoMar 27, 2026
  77. Ezekiel NewrenMar 30, 2026
  78. Junio C HamanoMar 30, 2026
  79. Ezekiel NewrenMar 31, 2026
  80. 5/6 xdiff/xdl_cleanup_records: make setting action easier to followEzekiel Newren via GitGitGadget, Mar 27, 2026
  81. 6/6 xdiff/xdl_cleanup_records: simplify INVESTIGATE handling for clarityEzekiel Newren via GitGitGadget, Mar 27, 2026
  82. 0/6 Xdiff cleanup part 3Ezekiel Newren via GitGitGadget, Mar 30, 2026
  83. 1/6 xdiff/xdl_cleanup_records: delete local recs pointerEzekiel Newren via GitGitGadget, Mar 30, 2026
  84. Ezekiel NewrenMar 30, 2026
  85. Junio C HamanoMar 30, 2026
  86. 2/6 xdiff: use unambiguous types in xdl_bogo_sqrt()Ezekiel Newren via GitGitGadget, Mar 30, 2026
  87. Junio C HamanoMar 30, 2026
  88. 3/6 xdiff/xdl_cleanup_records: use unambiguous typesEzekiel Newren via GitGitGadget, Mar 30, 2026
  89. 4/6 xdiff/xdl_cleanup_records: make limits more clearEzekiel Newren via GitGitGadget, Mar 30, 2026
  90. Phillip WoodMar 31, 2026
  91. Junio C HamanoMar 31, 2026
  92. Ezekiel NewrenApr 14, 2026
  93. Junio C HamanoApr 14, 2026
  94. Phillip WoodApr 15, 2026
  95. 5/6 xdiff/xdl_cleanup_records: make setting action easier to followEzekiel Newren via GitGitGadget, Mar 30, 2026
  96. Junio C HamanoMar 30, 2026
  97. Phillip WoodMar 31, 2026
  98. 6/6 xdiff/xdl_cleanup_records: simplify INVESTIGATE handling for clarityEzekiel Newren via GitGitGadget, Mar 30, 2026
  99. Phillip WoodMar 31, 2026
  100. Phillip WoodApr 1, 2026
  101. Junio C HamanoMar 30, 2026
  102. Phillip WoodMar 31, 2026
  103. 0/6 Xdiff cleanup part 3Ezekiel Newren via GitGitGadget, Apr 8, 2026
  104. 1/6 xdiff/xdl_cleanup_records: delete local recs pointerEzekiel Newren via GitGitGadget, Apr 8, 2026
  105. 2/6 xdiff: use unambiguous types in xdl_bogo_sqrt()Ezekiel Newren via GitGitGadget, Apr 8, 2026
  106. 3/6 xdiff/xdl_cleanup_records: use unambiguous typesEzekiel Newren via GitGitGadget, Apr 8, 2026
  107. 4/6 xdiff/xdl_cleanup_records: make limits more clearEzekiel Newren via GitGitGadget, Apr 8, 2026
  108. Phillip WoodApr 14, 2026
  109. 5/6 xdiff/xdl_cleanup_records: make setting action easier to followEzekiel Newren via GitGitGadget, Apr 8, 2026
  110. 6/6 xdiff/xdl_cleanup_records: put braces around the else clauseEzekiel Newren via GitGitGadget, Apr 8, 2026
  111. Junio C HamanoApr 8, 2026
  112. Phillip WoodApr 9, 2026
  113. Phillip WoodApr 14, 2026
  114. Junio C HamanoApr 14, 2026
  115. 0/6 Xdiff cleanup part 3Ezekiel Newren via GitGitGadget, Apr 29, 2026
  116. 1/6 xdiff/xdl_cleanup_records: delete local recs pointerEzekiel Newren via GitGitGadget, Apr 29, 2026
  117. 2/6 xdiff: use unambiguous types in xdl_bogo_sqrt()Ezekiel Newren via GitGitGadget, Apr 29, 2026
  118. 3/6 xdiff/xdl_cleanup_records: use unambiguous typesEzekiel Newren via GitGitGadget, Apr 29, 2026
  119. 4/6 xdiff/xdl_cleanup_records: make limits more clearEzekiel Newren via GitGitGadget, Apr 29, 2026
  120. 5/6 xdiff/xdl_cleanup_records: make setting action easier to followEzekiel Newren via GitGitGadget, Apr 29, 2026
  121. 6/6 xdiff/xdl_cleanup_records: make execution of action easier to followEzekiel Newren via GitGitGadget, Apr 29, 2026
  122. Phillip WoodApr 30, 2026
  123. Ezekiel NewrenApr 30, 2026
  124. Junio C HamanoMay 4, 2026

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.