Commit fef71b0
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.
Change-Id: Ie6b237417d302632f625ded4c19d204fce9a4caa1 parent a5b3a1b commit fef71b0
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