Commit 746c187
committed
Fix integer overflow in comparison function
The comparison function used in qsort() returns *a - *b, which can cause
integer overflow when the difference exceeds the range of int. This
leads to incorrect sorting results when execution time measurements
exceed approximately 2.1 billion cycles, which is possible in certain
cases.
Fix this by returning -1, 0, or 1 explicitly based on the comparison of
*a and *b, avoiding overflow while maintaining correct sorting behavior.1 parent 54603f2 commit 746c187
1 file changed
+3
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
0 commit comments