From: Jim Meyering Date: Sun, 10 Aug 2008 14:13:14 +0000 (+0200) Subject: sort: avoid erroneous cast X-Git-Tag: v7.0~93 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43f66923ccaf0f3ba6969e43762602fdaafbe912;p=platform%2Fupstream%2Fcoreutils.git sort: avoid erroneous cast * src/sort.c (OPEN_MAX): Define if not already defined. (MAX_NMERGE): Remove definition. (specify_nmerge): Don't cast MAX_NMERGE (of type size_t) to unsigned int. Instead, use OPEN_MAX as the fall-back value. --- diff --git a/src/sort.c b/src/sort.c index 74318b9..a07ecfc 100644 --- a/src/sort.c +++ b/src/sort.c @@ -76,6 +76,13 @@ struct rlimit { size_t rlim_cur; }; # endif #endif +#if !defined OPEN_MAX && defined NR_OPEN +# define OPEN_MAX NR_OPEN +#endif +#if !defined OPEN_MAX +# define OPEN_MAX 20 +#endif + #ifndef STDC_HEADERS double strtod (); #endif @@ -231,9 +238,6 @@ static struct month monthtab[] = /* Minimum sort size; the code might not work with smaller sizes. */ #define MIN_SORT_SIZE (nmerge * MIN_MERGE_BUFFER_SIZE) -/* Maximum merge buffers we can theoretically support */ -#define MAX_NMERGE (SIZE_MAX / MIN_MERGE_BUFFER_SIZE) - /* The number of bytes needed for a merge or check buffer, which can function relatively efficiently even if it holds only one line. If a longer line is seen, this value is increased. */ @@ -1075,14 +1079,15 @@ specify_nmerge (int oi, char c, char const *s) { uintmax_t n; struct rlimit rlimit; - unsigned int max_nmerge = (unsigned int) MAX_NMERGE; enum strtol_error e = xstrtoumax (s, NULL, 10, &n, NULL); /* Try to find out how many file descriptors we'll be able to open. We need at least nmerge + 3 (STDIN_FILENO, STDOUT_FILENO and STDERR_FILENO). */ - if (getrlimit (RLIMIT_NOFILE, &rlimit) == 0) - max_nmerge = MIN (max_nmerge, rlimit.rlim_cur - 3); + unsigned int max_nmerge = ((getrlimit (RLIMIT_NOFILE, &rlimit) == 0 + ? rlimit.rlim_cur + : OPEN_MAX) + - 3); if (e == LONGINT_OK) {