* src/sort.c (keycompare, compare): Don’t overflow if -r is
specified and a comparison function returns INT_MIN, as this
causes the comparison to have undefined behavior (typically the
reverse of correct). glibc memcmp on s390x reportedly returns
INT_MIN in some cases, so this is not a purely academic issue.
}
}
- return key->reverse ? -diff : diff;
+ if (key->reverse)
+ diff = diff < 0 ? -1 : -diff;
+ return diff;
}
/* Compare two lines A and B, returning negative, zero, or positive
diff = (alen > blen) - (alen < blen);
}
- return reverse ? -diff : diff;
+ if (reverse)
+ diff = diff < 0 ? 1 : -diff;
+ return diff;
}
/* Write LINE to output stream FP; the output file's name is