Skip to content

Commit e85a416

Browse files
ezekielnewrengitster
authored andcommitted
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>
1 parent da1a90e commit e85a416

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

xdiff/xdiffi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
348348
kvdf += xe->xdf2.nreff + 1;
349349
kvdb += xe->xdf2.nreff + 1;
350350

351-
xenv.mxcost = xdl_bogosqrt(ndiags);
351+
xenv.mxcost = (long)xdl_bogosqrt((uint64_t)ndiags);
352352
if (xenv.mxcost < XDL_MAX_COST_MIN)
353353
xenv.mxcost = XDL_MAX_COST_MIN;
354354
xenv.snake_cnt = XDL_SNAKE_CNT;

xdiff/xprepare.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
290290
/*
291291
* Initialize temporary arrays with DISCARD, KEEP, or INVESTIGATE.
292292
*/
293-
if ((mlim = xdl_bogosqrt((long)xdf1->nrec)) > XDL_MAX_EQLIMIT)
293+
if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf1->nrec)) > XDL_MAX_EQLIMIT)
294294
mlim = XDL_MAX_EQLIMIT;
295295
for (i = xdf1->dstart; i <= xdf1->dend; i++) {
296296
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
299299
action1[i] = (nm == 0) ? DISCARD: (nm >= mlim && !need_min) ? INVESTIGATE: KEEP;
300300
}
301301

302-
if ((mlim = xdl_bogosqrt((long)xdf2->nrec)) > XDL_MAX_EQLIMIT)
302+
if ((mlim = (long)xdl_bogosqrt((uint64_t)xdf2->nrec)) > XDL_MAX_EQLIMIT)
303303
mlim = XDL_MAX_EQLIMIT;
304304
for (i = xdf2->dstart; i <= xdf2->dend; i++) {
305305
size_t mph2 = xdf2->recs[i].minimal_perfect_hash;

xdiff/xutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "xinclude.h"
2424

2525

26-
long xdl_bogosqrt(long n) {
27-
long i;
26+
uint64_t xdl_bogosqrt(uint64_t n) {
27+
uint64_t i;
2828

2929
/*
3030
* Classical integer square root approximation using shifts.

xdiff/xutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727

28-
long xdl_bogosqrt(long n);
28+
uint64_t xdl_bogosqrt(uint64_t n);
2929
int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
3030
xdemitcb_t *ecb);
3131
int xdl_cha_init(chastore_t *cha, long isize, long icount);

0 commit comments

Comments
 (0)