xdiff: use unambiguous types in xdl_bogo_sqrt()

There is no real square root for a negative number and size_t may not be large enough for certain applications, replace long with uint64_t. Signed-off-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ezekiel Newren committed Apr 29, 2026 at 22:08 UTC c37f8cda0525d7041d9a22e477117a2962f9f675
4 files changed +6 -6
xdiff/xdiffi.c
+1 -1
@@ -348,7 +348,7 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
348 kvdf += xe->xdf2.nreff + 1;
349 kvdb += xe->xdf2.nreff + 1;
350
351 - xenv.mxcost = xdl_bogosqrt(ndiags);
351 + xenv.mxcost = (long)xdl_bogosqrt((uint64_t)ndiags);
352 if (xenv.mxcost < XDL_MAX_COST_MIN)
353 xenv.mxcost = XDL_MAX_COST_MIN;
354 xenv.snake_cnt = XDL_SNAKE_CNT;
xdiff/xprepare.c
+2 -2
@@ -290,7 +290,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
290 /*
291 * Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
292 */
293 - if ((mlim = xdl_bogosqrt((long)xdf1->nrec)) > XDL_MAX_EQLIMIT)
293 + if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf1->nrec)) > XDL_MAX_EQLIMIT)
294 mlim = XDL_MAX_EQLIMIT;
295 for (i = xdf1->dstart; i <= xdf1->dend; i++) {
296 size_t mph1 = xdf1->recs[i].minimal_perfect_hash;
@@ -299,7 +299,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
299 action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
300 }
301
302 - if ((mlim = xdl_bogosqrt((long)xdf2->nrec)) > XDL_MAX_EQLIMIT)
302 + if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf2->nrec)) > XDL_MAX_EQLIMIT)
303 mlim = XDL_MAX_EQLIMIT;
304 for (i = xdf2->dstart; i <= xdf2->dend; i++) {
305 size_t mph2 = xdf2->recs[i].minimal_perfect_hash;
xdiff/xutils.c
+2 -2
@@ -23,8 +23,8 @@
23 #include "xinclude.h"
24
25
26 -long xdl_bogosqrt(long n) {
27 - long i;
26 +uint64_t xdl_bogosqrt(uint64_t n) {
27 + uint64_t i;
28
29 /*
30 * Classical integer square root approximation using shifts.
xdiff/xutils.h
+1 -1
@@ -25,7 +25,7 @@
25
26
27
28 -long xdl_bogosqrt(long n);
28 +uint64_t xdl_bogosqrt(uint64_t n);
29 int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
30 xdemitcb_t *ecb);
31 int xdl_cha_init(chastore_t *cha, long isize, long icount);