[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fix a minor bug in sort: bogus --batch-size diagnostic
From: |
Jim Meyering |
Subject: |
fix a minor bug in sort: bogus --batch-size diagnostic |
Date: |
Sun, 10 Aug 2008 17:20:58 +0200 |
I noticed that ./sort -m --batch-size=18446744073709551617
was printing garbage as part of its diagnostic.
Here's the fix, along with a couple other improvements.
>From cd1f4bc1ecde1e7b313c1d0d587a07965d00d8b1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 10 Aug 2008 10:51:03 +0200
Subject: [PATCH] sort: don't print uninitialized in diagnostic
* src/sort.c (specify_nmerge): Do use uinttostr value.
Provoke with e.g., sort -m --batch-size=18446744073709551617
Omit quotes around known-numeric value in diagnostic.
* tests/misc/sort-merge [nmerge-big]: Tighten ERR_SUBST regexp
to require a numeric value in that diagnostic, so this particular
failure cannot reappear.
---
src/sort.c | 4 ++--
tests/misc/sort-merge | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/sort.c b/src/sort.c
index 9f998a6..74318b9 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1111,12 +1111,12 @@ specify_nmerge (int oi, char c, char const *s)
if (e == LONGINT_OVERFLOW)
{
char max_nmerge_buf[INT_BUFSIZE_BOUND (unsigned int)];
- uinttostr (max_nmerge, max_nmerge_buf);
error (0, 0, _("--%s argument %s too large"),
long_options[oi].name, quote(s));
error (SORT_FAILURE, 0,
_("maximum --%s argument with current rlimit is %s"),
- long_options[oi].name, quote (max_nmerge_buf));
+ long_options[oi].name,
+ uinttostr (max_nmerge, max_nmerge_buf));
}
else
xstrtol_fatal (e, oi, c, long_options, s);
diff --git a/tests/misc/sort-merge b/tests/misc/sort-merge
index fb7c63c..985d7a4 100755
--- a/tests/misc/sort-merge
+++ b/tests/misc/sort-merge
@@ -55,9 +55,9 @@ my @Tests =
{ERR=>"$prog: invalid --batch-size argument `a'\n"}, {EXIT=>2}],
['nmerge-big', "-m --batch-size=$bigint", @inputs,
- {ERR_SUBST=>'s/current rlimit is .+\n/current rlimit is/'},
+ {ERR_SUBST=>'s/(current rlimit is) \d+/$1/'},
{ERR=>"$prog: --batch-size argument `$bigint' too large\n".
- "$prog: maximum --batch-size argument with current rlimit is"},
+ "$prog: maximum --batch-size argument with current rlimit is\n"},
{EXIT=>2}],
# This should work since nmerge >= the number of input files
--
1.6.0.rc2.24.g3cd61
>From 43f66923ccaf0f3ba6969e43762602fdaafbe912 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 10 Aug 2008 16:13:14 +0200
Subject: [PATCH] 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.
---
src/sort.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
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)
{
--
1.6.0.rc2.24.g3cd61
>From 4b5e044be39c4699adfe499bd100d19613a98c58 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 10 Aug 2008 16:15:00 +0200
Subject: [PATCH] sort: remove unnecessary declaration of strtod
* src/sort.c (STDC_HEADERS): Remove declaration of strtod.
---
src/sort.c | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/src/sort.c b/src/sort.c
index a07ecfc..b932a51 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -83,10 +83,6 @@ struct rlimit { size_t rlim_cur; };
# define OPEN_MAX 20
#endif
-#ifndef STDC_HEADERS
-double strtod ();
-#endif
-
#define UCHAR_LIM (UCHAR_MAX + 1)
#ifndef DEFAULT_TMPDIR
--
1.6.0.rc2.24.g3cd61
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- fix a minor bug in sort: bogus --batch-size diagnostic,
Jim Meyering <=