]> git.saurik.com Git - bison.git/commitdiff
use obstack_printf
authorAkim Demaille <akim@lrde.epita.fr>
Mon, 30 Jul 2012 16:05:10 +0000 (18:05 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Tue, 31 Jul 2012 08:50:06 +0000 (10:50 +0200)
This is not just nicer, it is also much safer, since we were
using sprintf...

* bootstrap.conf: Require it.
* src/system.h (obstack_fgrow1, obstack_fgrow2, obstack_fgrow3)
(obstack_fgrow4): Remove.
Adjust dependencies.

bootstrap.conf
lib/.gitignore
m4/.gitignore
src/conflicts.c
src/muscle-tab.c
src/muscle-tab.h
src/output.c
src/print_graph.c
src/scan-code.l
src/system.h

index aa05e340d84b10a2dbbb3cea9a788666fe757298..165d5e7d84675cbae6edc6dd123b2ba74f8ed596 100644 (file)
@@ -24,7 +24,10 @@ gnulib_modules='
   gettext git-version-gen gitlog-to-changelog
   gpl-3.0 hash inttypes isnan javacomp-script
   javaexec-script ldexpl malloc-gnu mbschr mbsrchr
-  mbswidth obstack perror progname
+  mbswidth
+  obstack
+  obstack-printf
+  perror progname
   quote quotearg
   readme-release
   realloc-posix
index 5eec7430329143d48d545e029db195234b7f9ab4..964d7f4525e629602cd58fdb828b265652bba4e3 100644 (file)
 /xmemdup0.c
 /xmemdup0.h
 /sys_types.in.h
+/obstack_printf.c
index 8a24eb00f3cc03331f4732084a2375c72203e993..797ed6df9ceb6e4498ba6c2097b3e595ea1cc40b 100644 (file)
 /xalloc.m4
 /xsize.m4
 /xstrndup.m4
+/obstack-printf.m4
index 9af53a6793ebbf7e062b92b60e36df0f0dafb3e3..ba0b6ed3fe80af1d657060d76670c5ecd6f16340 100644 (file)
@@ -73,7 +73,7 @@ log_resolution (rule *r, symbol_number token,
        {
        case shift_resolution:
        case right_resolution:
-         obstack_fgrow2 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          _("    Conflict between rule %d and token %s"
                            " resolved as shift"),
                          r->number,
@@ -82,7 +82,7 @@ log_resolution (rule *r, symbol_number token,
 
        case reduce_resolution:
        case left_resolution:
-         obstack_fgrow2 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          _("    Conflict between rule %d and token %s"
                            " resolved as reduce"),
                          r->number,
@@ -90,7 +90,7 @@ log_resolution (rule *r, symbol_number token,
          break;
 
        case nonassoc_resolution:
-         obstack_fgrow2 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          _("    Conflict between rule %d and token %s"
                            " resolved as an error"),
                          r->number,
@@ -102,33 +102,33 @@ log_resolution (rule *r, symbol_number token,
       switch (resolution)
        {
        case shift_resolution:
-         obstack_fgrow2 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          " (%s < %s)",
                          r->prec->tag,
                          symbols[token]->tag);
          break;
 
        case reduce_resolution:
-         obstack_fgrow2 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          " (%s < %s)",
                          symbols[token]->tag,
                          r->prec->tag);
          break;
 
        case left_resolution:
-         obstack_fgrow1 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          " (%%left %s)",
                          symbols[token]->tag);
          break;
 
        case right_resolution:
-         obstack_fgrow1 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          " (%%right %s)",
                          symbols[token]->tag);
          break;
 
        case nonassoc_resolution:
-         obstack_fgrow1 (&solved_conflicts_obstack,
+         obstack_printf (&solved_conflicts_obstack,
                          " (%%nonassoc %s)",
                          symbols[token]->tag);
          break;
@@ -145,7 +145,7 @@ log_resolution (rule *r, symbol_number token,
         {
         case shift_resolution:
         case right_resolution:
-          obstack_fgrow2 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "        <resolution rule=\"%d\" symbol=\"%s\""
                           " type=\"shift\">",
                           r->number,
@@ -154,7 +154,7 @@ log_resolution (rule *r, symbol_number token,
 
         case reduce_resolution:
         case left_resolution:
-          obstack_fgrow2 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "        <resolution rule=\"%d\" symbol=\"%s\""
                           " type=\"reduce\">",
                           r->number,
@@ -162,7 +162,7 @@ log_resolution (rule *r, symbol_number token,
           break;
 
         case nonassoc_resolution:
-          obstack_fgrow2 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "        <resolution rule=\"%d\" symbol=\"%s\""
                           " type=\"error\">",
                           r->number,
@@ -174,33 +174,33 @@ log_resolution (rule *r, symbol_number token,
       switch (resolution)
         {
         case shift_resolution:
-          obstack_fgrow2 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "%s &lt; %s",
                           xml_escape_n (0, r->prec->tag),
                           xml_escape_n (1, symbols[token]->tag));
           break;
 
         case reduce_resolution:
-          obstack_fgrow2 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "%s &lt; %s",
                           xml_escape_n (0, symbols[token]->tag),
                           xml_escape_n (1, r->prec->tag));
           break;
 
         case left_resolution:
-          obstack_fgrow1 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "%%left %s",
                           xml_escape (symbols[token]->tag));
           break;
 
         case right_resolution:
-          obstack_fgrow1 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "%%right %s",
                           xml_escape (symbols[token]->tag));
           break;
 
         case nonassoc_resolution:
-          obstack_fgrow1 (&solved_conflicts_xml_obstack,
+          obstack_printf (&solved_conflicts_xml_obstack,
                           "%%nonassoc %s",
                           xml_escape (symbols[token]->tag));
       break;
index 5c624982a9a7795cfd3dfb5b17aa53c5aa97f0fe..bd1fd174719941c0ea86b2e727e34404d6dbf13f 100644 (file)
@@ -177,7 +177,7 @@ static void
 muscle_syncline_grow (char const *key, location loc)
 {
   char *extension = NULL;
-  obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
+  obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
   obstack_quote (&muscle_obstack,
                  quotearg_style (c_quoting_style, loc.start.file));
   obstack_sgrow (&muscle_obstack, ")[");
@@ -269,9 +269,9 @@ muscle_boundary_grow (char const *key, boundary bound)
   obstack_sgrow  (&muscle_obstack, "[[");
   obstack_escape (&muscle_obstack, bound.file);
   obstack_1grow  (&muscle_obstack, ':');
-  obstack_fgrow1 (&muscle_obstack, "%d", bound.line);
+  obstack_printf (&muscle_obstack, "%d", bound.line);
   obstack_1grow  (&muscle_obstack, '.');
-  obstack_fgrow1 (&muscle_obstack, "%d", bound.column);
+  obstack_printf (&muscle_obstack, "%d", bound.column);
   obstack_sgrow  (&muscle_obstack, "]]");
   obstack_1grow  (&muscle_obstack, '\0');
   extension = obstack_finish (&muscle_obstack);
index ddbad4085572477af12b7477295c01ca829c2e89..696103f393f161b69e93afd882ca019c40656300 100644 (file)
@@ -43,14 +43,14 @@ extern struct obstack muscle_obstack;
 
 #define MUSCLE_INSERT_INT(Key, Value)                           \
   do {                                                          \
-    obstack_fgrow1 (&muscle_obstack, "%d", Value);              \
+    obstack_printf (&muscle_obstack, "%d", Value);              \
     obstack_1grow (&muscle_obstack, 0);                         \
     muscle_insert (Key, obstack_finish (&muscle_obstack));      \
   } while (0)
 
 #define MUSCLE_INSERT_LONG_INT(Key, Value)                      \
   do {                                                          \
-    obstack_fgrow1 (&muscle_obstack, "%ld", Value);             \
+    obstack_printf (&muscle_obstack, "%ld", Value);             \
     obstack_1grow (&muscle_obstack, 0);                         \
     muscle_insert (Key, obstack_finish (&muscle_obstack));      \
   } while (0)
index d52a711393cf960b73c0a55ad8f69d752d699096..e77a2d1a0fc85a75d6f6bec202d96351778dfef2 100644 (file)
@@ -70,7 +70,7 @@ Name (char const *name,                                                       \
   int i;                                                               \
   int j = 1;                                                           \
                                                                        \
-  obstack_fgrow1 (&format_obstack, "%6d", first);                      \
+  obstack_printf (&format_obstack, "%6d", first);                      \
   for (i = begin; i < end; ++i)                                                \
     {                                                                  \
       obstack_1grow (&format_obstack, ',');                            \
@@ -81,7 +81,7 @@ Name (char const *name,                                                       \
        }                                                               \
       else                                                             \
        ++j;                                                            \
-      obstack_fgrow1 (&format_obstack, "%6d", table_data[i]);          \
+      obstack_printf (&format_obstack, "%6d", table_data[i]);          \
       if (table_data[i] < min)                                         \
        min = table_data[i];                                            \
       if (max < table_data[i])                                         \
@@ -93,10 +93,10 @@ Name (char const *name,                                                     \
   lmin = min;                                                          \
   lmax = max;                                                          \
   /* Build `NAME_min' and `NAME_max' in the obstack. */                        \
-  obstack_fgrow1 (&format_obstack, "%s_min", name);                    \
+  obstack_printf (&format_obstack, "%s_min", name);                    \
   obstack_1grow (&format_obstack, 0);                                  \
   MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmin);     \
-  obstack_fgrow1 (&format_obstack, "%s_max", name);                    \
+  obstack_printf (&format_obstack, "%s_max", name);                    \
   obstack_1grow (&format_obstack, 0);                                  \
   MUSCLE_INSERT_LONG_INT (obstack_finish (&format_obstack), lmax);     \
 }
index 8571e147b5cef0b2a049d9caf226ec32c0faddfa..f5695a7a734951fe65d5d498359f3fd66522292f 100644 (file)
@@ -54,7 +54,7 @@ print_core (struct obstack *oout, state *s)
       snritems = nitemset;
     }
 
-  obstack_fgrow1 (oout, "%d", s->number);
+  obstack_printf (oout, "%d", s->number);
   for (i = 0; i < snritems; i++)
     {
       item_number *sp;
@@ -68,15 +68,15 @@ print_core (struct obstack *oout, state *s)
 
       r = item_number_as_rule_number (*sp);
 
-      obstack_fgrow1 (oout, "\n%s -> ", rules[r].lhs->tag);
+      obstack_printf (oout, "\n%s -> ", rules[r].lhs->tag);
 
       for (sp = rules[r].rhs; sp < sp1; sp++)
-       obstack_fgrow1 (oout, "%s ", symbols[*sp]->tag);
+       obstack_printf (oout, "%s ", symbols[*sp]->tag);
 
       obstack_1grow (oout, '.');
 
       for (/* Nothing */; *sp >= 0; ++sp)
-       obstack_fgrow1 (oout, " %s", symbols[*sp]->tag);
+       obstack_printf (oout, " %s", symbols[*sp]->tag);
 
       /* Experimental feature: display the lookahead tokens. */
       if (report_flag & report_lookahead_tokens
@@ -95,7 +95,7 @@ print_core (struct obstack *oout, state *s)
              obstack_sgrow (oout, "[");
              BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
                {
-                 obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag);
+                 obstack_printf (oout, "%s%s", sep, symbols[k]->tag);
                  sep = ", ";
                }
              obstack_sgrow (oout, "]");
index 31befe9172f9bc7e8d6c99f543e4f8c5649ff2af..fa593beb8da889aeeb3c9685dacf0497f7422508 100644 (file)
@@ -443,30 +443,30 @@ show_sub_messages (const char* cp, bool explicit_bracketing,
          /* Create the explanation message. */
          obstack_init (&msg_buf);
 
-         obstack_fgrow1 (&msg_buf, _("possibly meant: %c"), dollar_or_at);
+         obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at);
          if (contains_dot_or_dash (id))
-           obstack_fgrow1 (&msg_buf, "[%s]", id);
+           obstack_printf (&msg_buf, "[%s]", id);
          else
            obstack_sgrow (&msg_buf, id);
          obstack_sgrow (&msg_buf, tail);
 
          if (var->err & VARIANT_HIDDEN)
            {
-             obstack_fgrow1 (&msg_buf, _(", hiding %c"), dollar_or_at);
+             obstack_printf (&msg_buf, _(", hiding %c"), dollar_or_at);
              if (contains_dot_or_dash (var->id))
-               obstack_fgrow1 (&msg_buf, "[%s]", var->id);
+               obstack_printf (&msg_buf, "[%s]", var->id);
              else
                obstack_sgrow (&msg_buf, var->id);
              obstack_sgrow (&msg_buf, tail);
            }
 
-         obstack_fgrow1 (&msg_buf, _(" at %s"), at_spec);
+         obstack_printf (&msg_buf, _(" at %s"), at_spec);
 
          if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
             {
               const char *format =
                 _(", cannot be accessed from mid-rule action at $%d");
-              obstack_fgrow1 (&msg_buf, format, midrule_rhs_index);
+              obstack_printf (&msg_buf, format, midrule_rhs_index);
             }
 
          obstack_1grow (&msg_buf, '\0');
@@ -788,7 +788,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
             untyped_var_seen = true;
         }
 
-      obstack_fgrow2 (&obstack_for_string,
+      obstack_printf (&obstack_for_string,
                      "]b4_rhs_value(%d, %d, ", effective_rule_length, n);
       obstack_quote (&obstack_for_string, type_name);
       obstack_sgrow (&obstack_for_string, ")[");
@@ -838,7 +838,7 @@ handle_action_at (symbol_list *rule, char *text, location at_loc)
       break;
 
     default:
-      obstack_fgrow2 (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
+      obstack_printf (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
                      effective_rule_length, n);
       break;
     }
index 06fd0f0a9d578901a14b14a3e4804dc4f660142d..1ae6a6b44a5921e9ca8bec6d65fac6eabb1d1b93 100644 (file)
@@ -163,35 +163,6 @@ typedef size_t uintptr_t;
 # define obstack_sgrow(Obs, Str)                \
   obstack_grow (Obs, Str, strlen (Str))
 
-# define obstack_fgrow1(Obs, Format, Arg1)      \
-  do {                                          \
-    char buf[4096];                             \
-    sprintf (buf, Format, Arg1);                \
-    obstack_grow (Obs, buf, strlen (buf));      \
-  } while (0)
-
-# define obstack_fgrow2(Obs, Format, Arg1, Arg2)        \
-  do {                                                  \
-    char buf[4096];                                     \
-    sprintf (buf, Format, Arg1, Arg2);                  \
-    obstack_grow (Obs, buf, strlen (buf));              \
-  } while (0)
-
-# define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3)  \
-  do {                                                  \
-    char buf[4096];                                     \
-    sprintf (buf, Format, Arg1, Arg2, Arg3);            \
-    obstack_grow (Obs, buf, strlen (buf));              \
-  } while (0)
-
-# define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4)    \
-  do {                                                          \
-    char buf[4096];                                             \
-    sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4);              \
-    obstack_grow (Obs, buf, strlen (buf));                      \
-  } while (0)
-
-
 /* Output Str escaped for our postprocessing (i.e., escape M4 special
    characters).