m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

head - warn on builtin with too few arguments


From: Eric Blake
Subject: head - warn on builtin with too few arguments
Date: Mon, 21 Aug 2006 02:36:44 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

This is a port of the following patches on the branch:
http://www.nabble.com/Re%3A-branch-1_4-doc-improvements-p5336769.html
http://www.nabble.com/Re%3A-rfc%3A-new-__program__-macro-p5650125.html

2006-08-20  Eric Blake  <address@hidden>

        * m4/macro.c (expand_macro): Move argument check...
        (m4_macro_call): ...to here, so indir will warn.
        * modules/gnu.c (__program__): New macro, ported from branch.
        (builtin): Perform argument check.
        (changesyntax): Avoid out-of-bounds read.

Index: m4/macro.c
===================================================================
RCS file: /sources/m4/m4/m4/macro.c,v
retrieving revision 1.48
diff -u -p -r1.48 macro.c
--- m4/macro.c  16 Aug 2006 12:23:05 -0000      1.48
+++ m4/macro.c  21 Aug 2006 02:31:27 -0000
@@ -254,9 +254,7 @@ recursion limit of %d exceeded, use -L<N
     trace_pre (context, name, my_call_id, argc, argv);
 
   expansion = m4_push_string_init (context);
-  if (!m4_bad_argc (context, argc, argv,
-                   SYMBOL_MIN_ARGS (symbol), SYMBOL_MAX_ARGS (symbol)))
-    m4_macro_call (context, symbol, expansion, argc, argv);
+  m4_macro_call (context, symbol, expansion, argc, argv);
   expanded = m4_push_string_finish ();
 
   if (traced)
@@ -319,6 +317,9 @@ void
 m4_macro_call (m4 *context, m4_symbol *symbol, m4_obstack *expansion,
               int argc, m4_symbol_value **argv)
 {
+  if (m4_bad_argc (context, argc, argv,
+                  SYMBOL_MIN_ARGS (symbol), SYMBOL_MAX_ARGS (symbol)))
+    return;
   if (m4_is_symbol_text (symbol))
     {
       process_macro (context, symbol, expansion, argc, argv);
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.47
diff -u -p -r1.47 gnu.c
--- modules/gnu.c       21 Aug 2006 00:14:54 -0000      1.47
+++ modules/gnu.c       21 Aug 2006 02:31:27 -0000
@@ -33,6 +33,8 @@
 #  include "m4private.h"
 #endif
 
+#include "progname.h"
+
 /* Rename exported symbols for dlpreload()ing.  */
 #define m4_builtin_table       gnu_LTX_m4_builtin_table
 #define m4_macro_table         gnu_LTX_m4_macro_table
@@ -45,6 +47,7 @@
 #define builtin_functions                                      \
        BUILTIN(__file__,       false,  false,  1,      1  )    \
        BUILTIN(__line__,       false,  false,  1,      1  )    \
+       BUILTIN(__program__,    false,  false,  1,      1  )    \
        BUILTIN(builtin,        false,  true,   2,      -1 )    \
        BUILTIN(changeresyntax, false,  true,   1,      2  )    \
        BUILTIN(changesyntax,   false,  true,   1,      -1 )    \
@@ -289,6 +292,15 @@ M4BUILTIN_HANDLER (__line__)
 }
 
 
+/**
+ * __program__
+ **/
+M4BUILTIN_HANDLER (__program__)
+{
+  m4_shipout_string (context, obs, program_name, 0, true);
+}
+
+
 /* The builtin "builtin" allows calls to builtin macros, even if their
    definition has been overridden or shadowed.  It is thus possible to
    redefine builtins, and still access their original definition.  */
@@ -304,9 +316,10 @@ M4BUILTIN_HANDLER (builtin)
   bp = m4_builtin_find_by_name (NULL, name);
 
   if (bp == NULL)
-    m4_error (context, 0, 0, _("%s: undefined name `%s'"), M4ARG (0), name);
-  else
-    (*bp->func) (context, obs, argc - 1, argv + 1);
+    m4_error (context, 0, 0, _("%s: undefined builtin `%s'"), M4ARG (0), name);
+  else if (!m4_bad_argc (context, argc - 1, argv + 1,
+                        bp->min_args, bp->max_args))
+    bp->func (context, obs, argc - 1, argv + 1);
 }
 
 
@@ -356,9 +369,9 @@ M4BUILTIN_HANDLER (changesyntax)
       for (i = 1; i < argc; i++)
        {
          char key = *M4ARG (i);
-         if ((m4_set_syntax (M4SYNTAX, key,
-                             m4_expand_ranges (M4ARG (i)+1, obs)) < 0)
-             && (key != '\0'))
+         if (key != '\0'
+             && (m4_set_syntax (M4SYNTAX, key,
+                                m4_expand_ranges (M4ARG (i) + 1, obs)) < 0))
            {
              m4_error (context, 0, 0, _("%s: undefined syntax code: `%c'"),
                        M4ARG (0), key);
@@ -504,7 +517,7 @@ M4BUILTIN_HANDLER (indir)
   m4_symbol *  symbol = m4_symbol_lookup (M4SYMTAB, name);
 
   if (symbol == NULL)
-    m4_error (context, 0, 0, _("%s: undefined name `%s'"), M4ARG (0), name);
+    m4_error (context, 0, 0, _("%s: undefined macro `%s'"), M4ARG (0), name);
   else
     m4_macro_call (context, symbol, obs, argc - 1, argv + 1);
 }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]