summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2010-12-01 21:50:00 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2010-12-01 21:51:15 -0800
commit0ec869e8be853e19f8d98692a1867c5cddf9975b (patch)
tree0343dd0e90e153acabf2defde934a80a7aef59ea /src
parenta5207bb1391cb8e169bc6036eb036bb1a89cde89 (diff)
downloadcoreutils-0ec869e8be853e19f8d98692a1867c5cddf9975b.tar.xz
sort: fix bug on 64-bit hosts with at least 32768 processors
* src/sort.c (MAX_MERGE): Avoid integer overflow when on a machine with (say) 32-bit int and 64-bit size_t and when level == 15. Without this fix, on such a machine with 32768 or more processors, the level computation could overflow on large input, and this would result in division by zero.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/sort.c b/src/sort.c
index 1aa1eb416..5c368cd95 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -107,7 +107,7 @@ struct rlimit { size_t rlim_cur; };
/* Maximum number of lines to merge every time a NODE is taken from
the MERGE_QUEUE. Node is at LEVEL in the binary merge tree,
and is responsible for merging TOTAL lines. */
-#define MAX_MERGE(total, level) ((total) / ((2 << level) * (2 << level)) + 1)
+#define MAX_MERGE(total, level) (((total) >> (2 * ((level) + 1))) + 1)
/* Heuristic value for the number of lines for which it is worth
creating a subthread, during an internal merge sort, on a machine