Replace "if (x) free (x)" with "free (x)", bfd
[deliverable/binutils-gdb.git] / bfd / doc / chew.c
index c3dd9b444bfc93b1b24fd2059bea4ba44b820376..76cb09f7cf457f38c31aa492949e95855dadafb9 100644 (file)
@@ -1,5 +1,5 @@
 /* chew
-   Copyright (C) 1990-2019 Free Software Foundation, Inc.
+   Copyright (C) 1990-2020 Free Software Foundation, Inc.
    Contributed by steve chamberlain @cygnus
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -170,8 +170,7 @@ static void
 delete_string (buffer)
      string_type *buffer;
 {
-  if (buffer->ptr)
-    free (buffer->ptr);
+  free (buffer->ptr);
   buffer->ptr = NULL;
 }
 
@@ -1167,7 +1166,10 @@ nextword (string, word)
        }
     }
   if (!*string)
-    return 0;
+    {
+      *word = NULL;
+      return NULL;
+    }
 
   word_start = string;
   if (*string == '"')
@@ -1225,7 +1227,7 @@ nextword (string, word)
   if (*string)
     return string + 1;
   else
-    return 0;
+    return NULL;
 }
 
 dict_type *root;
@@ -1243,7 +1245,7 @@ lookup_word (word)
     }
   if (warning)
     fprintf (stderr, "Can't find %s\n", word);
-  return 0;
+  return NULL;
 }
 
 static void
@@ -1255,16 +1257,15 @@ free_words (void)
     {
       dict_type *next;
 
-      if (ptr->word)
-       free (ptr->word);
+      free (ptr->word);
       if (ptr->code)
        {
          int i;
-         for (i = 0; i < ptr->code_length; i ++)
+         for (i = 0; i < ptr->code_end - 1; i ++)
            if (ptr->code[i] == push_text
                && ptr->code[i + 1])
              {
-               free (ptr->code[i + 1] - 1);
+               free ((char *) ptr->code[i + 1] - 1);
                ++ i;
              }
          free (ptr->code);
@@ -1276,7 +1277,7 @@ free_words (void)
 }
 
 static void
-perform ()
+perform (void)
 {
   tos = stack;
 
@@ -1333,7 +1334,7 @@ add_to_definition (entry, word)
       entry->code_length += 2;
       entry->code =
        (stinst_type *) realloc ((char *) (entry->code),
-                                entry->code_length * sizeof (word_type));
+                                entry->code_length * sizeof (stinst_type));
     }
   entry->code[entry->code_end] = word;
 
@@ -1374,6 +1375,8 @@ compile (string)
        {
          free (word);
          string = nextword (string, &word);
+         if (!string)
+           continue;
          add_var (word);
          string = nextword (string, &word);
        }
@@ -1384,8 +1387,16 @@ compile (string)
          /* Compile a word and add to dictionary.  */
          free (word);
          string = nextword (string, &word);
+         if (!string)
+           continue;
          ptr = newentry (word);
          string = nextword (string, &word);
+         if (!string)
+           {
+             free (ptr->code);
+             free (ptr);
+             continue;
+           }
          
          while (word[0] != ';')
            {
@@ -1423,7 +1434,6 @@ compile (string)
            }
          add_to_definition (ptr, 0);
          free (word);
-         word = NULL;
          string = nextword (string, &word);
        }
       else
@@ -1431,8 +1441,7 @@ compile (string)
          fprintf (stderr, "syntax error at %s\n", string - 1);
        }
     }
-  if (word)
-    free (word);
+  free (word);
 }
 
 static void
This page took 0.025691 seconds and 4 git commands to generate.