]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: Add WARN_CFLAGS_FOR_BUILD to doc/chew.c build, fix warnings
authorMark Wielaard <mark@klomp.org>
Fri, 8 Nov 2024 10:57:30 +0000 (11:57 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 12 Nov 2024 21:39:33 +0000 (22:39 +0100)
doc/chew.c was compiled without any warning flags set. Adding the
common warnings for build showed various issues with non-static
functions missing prototypes and globals with common names (ptr and
idx) that shadowed local arguments or variables.

     * doc/local.mk (doc/chew.stamp): Add WARN_CFLAGS_FOR_BUILD.
     * Makefile.in: Regenerate.
     * doc/chew.c (idx): Rename to pos_idx.
     (ptr): Rename to buf_ptr.
     (xmalloc): Make static.
     (xrealloc): Likewise.
     (xstrdup): Likewise.
     (nextword): Likewise.
     (newentry): Likewise.
     (add_to_definition): Likewise.
     (add_intrinsic): Likewise.
     (compile): Likewise.
     (icopy_past_newline): Rename idx to pos_idx, ptr to buf_ptr.
     (get_stuff_in_command): Likewise.
     (skip_past_newline): Likewise.
     (perform): Likewise.
     (main): Likewise.

bfd/Makefile.in
bfd/doc/chew.c
bfd/doc/local.mk

index e9b479a8bdceeccbde06e42c2a3e315186e4ffa3..38364f4b2ba090a336cc8ea8544ab3dbfdff7622 100644 (file)
@@ -2497,7 +2497,7 @@ coff-tic54x.lo: coff-tic54x.c
 $(MKDOC): doc/chew.stamp ; @true
 doc/chew.stamp: $(srcdir)/doc/chew.c doc/$(am__dirstamp)
        $(AM_V_CCLD)$(CC_FOR_BUILD) -o doc/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
-         $(CPPFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) \
+         $(WARN_CFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) \
          -I. -I$(srcdir) -Idoc -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \
          $(srcdir)/doc/chew.c && \
        $(SHELL) $(srcdir)/../move-if-change \
index b0cb91448bef5b4d4dbd9728b1cc778beb96506b..469bd807f6961a7408cfe90d9bb42b8365f70fb5 100644 (file)
@@ -132,8 +132,8 @@ int warning;
 string_type stack[STACK];
 string_type *tos;
 
-unsigned int idx = 0; /* Pos in input buffer */
-string_type *ptr; /* and the buffer */
+unsigned int pos_idx = 0; /* Pos in input buffer */
+string_type *buf_ptr; /* and the buffer */
 
 intptr_t istack[STACK];
 intptr_t *isp = &istack[0];
@@ -149,7 +149,7 @@ die (char *msg)
   exit (1);
 }
 
-void *
+static void *
 xmalloc (size_t size)
 {
   void *newmem;
@@ -163,7 +163,7 @@ xmalloc (size_t size)
   return newmem;
 }
 
-void *
+static void *
 xrealloc (void *oldmem, size_t size)
 {
   void *newmem;
@@ -180,7 +180,7 @@ xrealloc (void *oldmem, size_t size)
   return newmem;
 }
 
-char *
+static char *
 xstrdup (const char *s)
 {
   size_t len = strlen (s) + 1;
@@ -837,7 +837,7 @@ icopy_past_newline (void)
   tos++;
   check_range ();
   init_string (tos);
-  idx = copy_past_newline (ptr, idx, tos);
+  pos_idx = copy_past_newline (buf_ptr, pos_idx, tos);
   pc++;
 }
 
@@ -1030,11 +1030,11 @@ get_stuff_in_command (void)
   check_range ();
   init_string (tos);
 
-  while (at (ptr, idx))
+  while (at (buf_ptr, pos_idx))
     {
-      if (iscommand (ptr, idx))
+      if (iscommand (buf_ptr, pos_idx))
        break;
-      idx = copy_past_newline (ptr, idx, tos);
+      pos_idx = copy_past_newline (buf_ptr, pos_idx, tos);
     }
   pc++;
 }
@@ -1073,7 +1073,7 @@ icatstr (void)
 static void
 skip_past_newline (void)
 {
-  idx = skip_past_newline_1 (ptr, idx);
+  pos_idx = skip_past_newline_1 (buf_ptr, pos_idx);
   pc++;
 }
 
@@ -1104,7 +1104,7 @@ catstrif (void)
   pc++;
 }
 
-char *
+static char *
 nextword (char *string, char **word)
 {
   char *word_start;
@@ -1192,7 +1192,7 @@ nextword (char *string, char **word)
     return NULL;
 }
 
-dict_type *
+static dict_type *
 lookup_word (char *word)
 {
   dict_type *ptr = root;
@@ -1245,15 +1245,15 @@ perform (void)
 {
   tos = stack;
 
-  while (at (ptr, idx))
+  while (at (buf_ptr, pos_idx))
     {
       /* It's worth looking through the command list.  */
-      if (iscommand (ptr, idx))
+      if (iscommand (buf_ptr, pos_idx))
        {
          char *next;
          dict_type *word;
 
-         (void) nextword (addr (ptr, idx), &next);
+         (void) nextword (addr (buf_ptr, pos_idx), &next);
 
          word = lookup_word (next);
 
@@ -1265,16 +1265,16 @@ perform (void)
            {
              if (warning)
                fprintf (stderr, "warning, %s is not recognised\n", next);
-             idx = skip_past_newline_1 (ptr, idx);
+             pos_idx = skip_past_newline_1 (buf_ptr, pos_idx);
            }
          free (next);
        }
       else
-       idx = skip_past_newline_1 (ptr, idx);
+       pos_idx = skip_past_newline_1 (buf_ptr, pos_idx);
     }
 }
 
-dict_type *
+static dict_type *
 newentry (char *word)
 {
   dict_type *new_d = xmalloc (sizeof (*new_d));
@@ -1287,7 +1287,7 @@ newentry (char *word)
   return new_d;
 }
 
-unsigned int
+static unsigned int
 add_to_definition (dict_type *entry, pcu word)
 {
   if (entry->code_end == entry->code_length)
@@ -1301,7 +1301,7 @@ add_to_definition (dict_type *entry, pcu word)
   return entry->code_end++;
 }
 
-void
+static void
 add_intrinsic (char *name, void (*func) (void))
 {
   dict_type *new_d = newentry (xstrdup (name));
@@ -1329,7 +1329,7 @@ add_intrinsic_variable (const char *name, intptr_t *loc)
   add_variable (xstrdup (name), loc);
 }
 
-void
+static void
 compile (char *string)
 {
   /* Add words to the dictionary.  */
@@ -1523,7 +1523,7 @@ main (int ac, char *av[])
   init_string (&pptr);
   init_string (stack + 0);
   tos = stack + 1;
-  ptr = &pptr;
+  buf_ptr = &pptr;
 
   add_intrinsic ("push_text", push_text);
   add_intrinsic ("!", bang);
@@ -1567,7 +1567,7 @@ main (int ac, char *av[])
   catchar (&buffer, '\n');
 
   read_in (&buffer, stdin);
-  remove_noncomments (&buffer, ptr);
+  remove_noncomments (&buffer, buf_ptr);
   for (i = 1; i < (unsigned int) ac; i++)
     {
       if (av[i][0] == '-')
index 9767e583f182d7d2c069ec562ae5ce7bc9a9bb56..346dba36b03c8d29acc0226e22c7b16ab518c026 100644 (file)
@@ -80,7 +80,7 @@ MKDOC = %D%/chew$(EXEEXT_FOR_BUILD)
 $(MKDOC): %D%/chew.stamp ; @true
 %D%/chew.stamp: $(srcdir)/%D%/chew.c %D%/$(am__dirstamp)
        $(AM_V_CCLD)$(CC_FOR_BUILD) -o %D%/chw$$$$$(EXEEXT_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
-         $(CPPFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) \
+         $(WARN_CFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) \
          -I. -I$(srcdir) -I%D% -I$(srcdir)/../include -I$(srcdir)/../intl -I../intl \
          $(srcdir)/%D%/chew.c && \
        $(SHELL) $(srcdir)/../move-if-change \