]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Use a well-known error string for out-of-bound function arguments
authorPaul Smith <psmith@gnu.org>
Sat, 18 Dec 2021 23:11:30 +0000 (18:11 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 19 Dec 2021 21:34:19 +0000 (16:34 -0500)
* src/function.c (parse_numeric): Check for empty value and error.
If we find ERANGE just print our own error, not strerror.
(func_word): Use a generic "not good" error message.
(func_wordlist): Ditto
(func_intcmp): Ditto
* tests/run_make_tests.pl: Remove code to find strerror(ERANGE)
* tests/scrips/functions/intcmp: Update the error message.
* tests/scrips/functions/word: Ditto.

src/function.c
tests/run_make_tests.pl
tests/scripts/functions/intcmp
tests/scripts/functions/word

index 0f9b609152d3933ab1048b6be220079e5808c766..af6ad135f1c432a8ea7ed706767da08f5259c1f1 100644 (file)
@@ -774,10 +774,13 @@ parse_numeric (const char *s, const char *msg)
   long long num;
   strip_whitespace (&beg, &end);
 
+  if (beg > end)
+    OS (fatal, *expanding_var, _("%s: empty value"), msg);
+
   errno = 0;
   num = strtoll (beg, &endp, 10);
   if (errno == ERANGE)
-    OSS (fatal, *expanding_var, "%s: '%s'", strerror (errno), s);
+    OSS (fatal, *expanding_var, _("%s: '%s' out of range"), msg, s);
   else if (endp == beg || endp <= end)
     /* Empty or non-numeric input */
     OSS (fatal, *expanding_var, "%s: '%s'", msg, s);
@@ -793,7 +796,7 @@ func_word (char *o, char **argv, const char *funcname UNUSED)
   long long i;
 
   i = parse_numeric (argv[0],
-                     _("non-numeric first argument to 'word' function"));
+                     _("invalid first argument to 'word' function"));
   if (i < 1)
     O (fatal, *expanding_var,
        _("first argument to 'word' function must be greater than 0"));
@@ -815,9 +818,9 @@ func_wordlist (char *o, char **argv, const char *funcname UNUSED)
   long long start, stop, count;
 
   start = parse_numeric (argv[0],
-                         _("non-numeric first argument to 'wordlist' function"));
+                         _("invalid first argument to 'wordlist' function"));
   stop = parse_numeric (argv[1],
-                        _("non-numeric second argument to 'wordlist' function"));
+                        _("invalid second argument to 'wordlist' function"));
 
   if (start < 1)
     ON (fatal, *expanding_var,
@@ -1295,9 +1298,9 @@ func_intcmp (char *o, char **argv, const char *funcname UNUSED)
   long long lhs, rhs;
 
   lhs = parse_numeric (lhs_str,
-                       _("non-numeric first argument to 'intcmp' function"));
+                       _("invalid first argument to 'intcmp' function"));
   rhs = parse_numeric (rhs_str,
-                       _("non-numeric second argument to 'intcmp' function"));
+                       _("invalid second argument to 'intcmp' function"));
   free (lhs_str);
   free (rhs_str);
 
index ebf202a29c851bfea92ed1c252c2fb9a83e731e2..4cc375e535a2741330e5d52469c06f23bf45b541 100644 (file)
@@ -108,7 +108,6 @@ $ERR_read_only_file = undef;
 $ERR_unreadable_file = undef;
 $ERR_nonexe_file = undef;
 $ERR_exe_dir = undef;
-$ERR_out_of_range = undef;
 
 {
   use locale;
@@ -122,9 +121,6 @@ $ERR_out_of_range = undef;
 
       # See set_defaults() as this doesn't work right on Windows :(
       $! = &POSIX::ERANGE;
-      $ERR_out_of_range = "$!";
-  } else {
-      $ERR_out_of_range = 'Numerical result out of range';
   }
 
   if (open(my $F, '<', 'file.none')) {
@@ -464,10 +460,6 @@ sub set_defaults
     $scriptsuffix = '.com';
   } else {
     $scriptsuffix = '.bat';
-
-    # Frustratingly, Perl reports the wrong strerror string for ERANGE.
-    # It's weird because Python gets it right.  Not sure what's going on.
-    $ERR_out_of_range = 'Result too large';
   }
 }
 
index eb58ae30b717537887d68e1d8dca06fedc86595c..6f3c1500f01b64fde0a4f3824805552612f18add 100644 (file)
@@ -42,17 +42,17 @@ intcmp-e3: ; @echo $(intcmp -1,9999999999999999999,foo)
 intcmp-e4: ; @echo $(intcmp -1)
 intcmp-e5: ; @echo $(intcmp ,55)',
               'intcmp-e1',
-              "#MAKEFILE#:2: *** non-numeric first argument to 'intcmp' function: '12a'.  Stop.",
+              "#MAKEFILE#:2: *** invalid first argument to 'intcmp' function: '12a'.  Stop.",
               512);
 
 run_make_test(undef,
               'intcmp-e2',
-              "#MAKEFILE#:3: *** non-numeric second argument to 'intcmp' function: ''.  Stop.",
+              "#MAKEFILE#:3: *** invalid second argument to 'intcmp' function: empty value.  Stop.",
               512);
 
 run_make_test(undef,
               'intcmp-e3',
-              "#MAKEFILE#:4: *** $ERR_out_of_range: '9999999999999999999'.  Stop.",
+              "#MAKEFILE#:4: *** invalid second argument to 'intcmp' function: '9999999999999999999' out of range.  Stop.",
               512);
 
 
index 1c87c4a1a501e46bb4b6d134117d194e2697d73e..217e693698db175b2374a4a54364d79edb6a7dba 100644 (file)
@@ -56,37 +56,37 @@ wordlist-e1: ; @echo $(wordlist ,,$(FOO))
 wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
 wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))',
               'word-e1',
-              "#MAKEFILE#:3: *** non-numeric first argument to 'word' function: ''.  Stop.",
+              "#MAKEFILE#:3: *** invalid first argument to 'word' function: empty value.  Stop.",
               512);
 
 run_make_test(undef,
               'word-e2',
-              "#MAKEFILE#:4: *** non-numeric first argument to 'word' function: 'abc '.  Stop.",
+              "#MAKEFILE#:4: *** invalid first argument to 'word' function: 'abc '.  Stop.",
               512);
 
 run_make_test(undef,
               'word-e3',
-              "#MAKEFILE#:5: *** non-numeric first argument to 'word' function: '1a'.  Stop.",
+              "#MAKEFILE#:5: *** invalid first argument to 'word' function: '1a'.  Stop.",
               512);
 
 run_make_test(undef,
               'word-e4',
-              "#MAKEFILE#:6: *** $ERR_out_of_range: '9999999999999999999'.  Stop.",
+              "#MAKEFILE#:6: *** invalid first argument to 'word' function: '9999999999999999999' out of range.  Stop.",
               512);
 
 run_make_test(undef,
               'wordlist-e1',
-              "#MAKEFILE#:8: *** non-numeric first argument to 'wordlist' function: ''.  Stop.",
+              "#MAKEFILE#:8: *** invalid first argument to 'wordlist' function: empty value.  Stop.",
               512);
 
 run_make_test(undef,
               'wordlist-e2',
-              "#MAKEFILE#:9: *** non-numeric first argument to 'wordlist' function: 'abc '.  Stop.",
+              "#MAKEFILE#:9: *** invalid first argument to 'wordlist' function: 'abc '.  Stop.",
               512);
 
 run_make_test(undef,
               'wordlist-e3',
-              "#MAKEFILE#:10: *** non-numeric second argument to 'wordlist' function: ' 12a '.  Stop.",
+              "#MAKEFILE#:10: *** invalid second argument to 'wordlist' function: ' 12a '.  Stop.",
               512);
 
 # Test error conditions again, but this time in a variable reference
@@ -99,12 +99,12 @@ WL = $(wordlist $s,$e,$(FOO))
 word-e: ; @echo $(W)
 wordlist-e: ; @echo $(WL)',
               'word-e x=',
-              "#MAKEFILE#:3: *** non-numeric first argument to 'word' function: ''.  Stop.",
+              "#MAKEFILE#:3: *** invalid first argument to 'word' function: empty value.  Stop.",
               512);
 
 run_make_test(undef,
               'word-e x=abc',
-              "#MAKEFILE#:3: *** non-numeric first argument to 'word' function: 'abc'.  Stop.",
+              "#MAKEFILE#:3: *** invalid first argument to 'word' function: 'abc'.  Stop.",
               512);
 
 run_make_test(undef,
@@ -114,17 +114,17 @@ run_make_test(undef,
 
 run_make_test(undef,
               'wordlist-e s= e=',
-              "#MAKEFILE#:4: *** non-numeric first argument to 'wordlist' function: ''.  Stop.",
+              "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: empty value.  Stop.",
               512);
 
 run_make_test(undef,
               'wordlist-e s=abc e=',
-              "#MAKEFILE#:4: *** non-numeric first argument to 'wordlist' function: 'abc'.  Stop.",
+              "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: 'abc'.  Stop.",
               512);
 
 run_make_test(undef,
               'wordlist-e s=4 e=12a',
-              "#MAKEFILE#:4: *** non-numeric second argument to 'wordlist' function: '12a'.  Stop.",
+              "#MAKEFILE#:4: *** invalid second argument to 'wordlist' function: '12a'.  Stop.",
               512);
 
 run_make_test(undef,