`pr -e=-1` gives a confusing error relating to just the "-1" portion,
when in fact "=" might have been inadvertently treated as a param.

* src/pr.c (getoptarg): Output the complete passed argument,
to avoid the confusion with "=" being used with a short option.
* tests/pr/options.sh: Adjust accordingly.

Link: https://github.com/coreutils/coreutils/issues/375
---
 src/pr.c            | 14 ++++++++------
 tests/pr/options.sh |  2 +-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/pr.c b/src/pr.c
index c3e085bcd..29321e58e 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -1169,18 +1169,20 @@ getoptnum (char const *n_str, int min, char const *err)
 static void
 getoptarg (char *arg, char switch_char, char *character, int *number)
 {
-  if (!*arg)
+  char const *num = arg;
+
+  if (!*num)
     {
-      error (0, 0, _("'-%c': Invalid argument: %s"), switch_char, quote (arg));
+      error (0, 0, _("'-%c': Invalid argument: %s"), switch_char, quote (num));
       usage (EXIT_FAILURE);
     }
 
-  if (!c_isdigit (*arg))
-    *character = *arg++;
-  if (*arg)
+  if (!c_isdigit (*num))
+    *character = *num++;
+  if (*num)
     {
       long int tmp_long;
-      strtol_error e = xstrtol (arg, NULL, 10, &tmp_long, "");
+      strtol_error e = xstrtol (num, NULL, 10, &tmp_long, "");
       if (e == LONGINT_OK)
         {
           if (tmp_long <= 0)
diff --git a/tests/pr/options.sh b/tests/pr/options.sh
index 2324eb57e..f12329cca 100755
--- a/tests/pr/options.sh
+++ b/tests/pr/options.sh
@@ -52,7 +52,7 @@ for w in w W; do
 done
 
 returns_ 1 pr -e=-1 2>err </dev/null || fail=1
-printf '%s\n' "pr: '-e' extra characters or $INV in the argument: '-1'" \
+printf '%s\n' "pr: '-e' extra characters or $INV in the argument: '=-1'" \
               "Try 'pr --help' for more information." \
  >exp || framework_failure_
 compare exp err || fail=1
-- 
2.55.0


Reply via email to