Skip to content

Commit 42c456f

Browse files
rscharfegitster
authored andcommitted
mergesort: avoid left shift overflow
Use size_t to match n when building the bitmask for checking whether a rank is occupied, instead of the default signed int. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c90cfc2 commit 42c456f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mergesort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void *llist_mergesort(void *list,
6363
void *next = get_next_fn(list);
6464
if (next)
6565
set_next_fn(list, NULL);
66-
for (i = 0; n & (1 << i); i++)
66+
for (i = 0; n & ((size_t)1 << i); i++)
6767
list = llist_merge(ranks[i], list, get_next_fn,
6868
set_next_fn, compare_fn);
6969
n++;

0 commit comments

Comments
 (0)