/* chew
- Copyright (C) 1990-2014 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.
delete_string (buffer)
string_type *buffer;
{
- free (buffer->ptr);
+ if (buffer->ptr)
+ free (buffer->ptr);
+ buffer->ptr = NULL;
}
static char *
{
tos--;
check_range ();
+ delete_string (tos + 1);
pc++;
}
}
}
if (!*string)
- return 0;
+ {
+ *word = NULL;
+ return NULL;
+ }
word_start = string;
if (*string == '"')
if (*string)
return string + 1;
else
- return 0;
+ return NULL;
}
dict_type *root;
}
if (warning)
fprintf (stderr, "Can't find %s\n", word);
- return 0;
+ return NULL;
}
static void
-perform ()
+free_words (void)
+{
+ dict_type *ptr = root;
+
+ while (ptr)
+ {
+ dict_type *next;
+
+ if (ptr->word)
+ free (ptr->word);
+ if (ptr->code)
+ {
+ int i;
+ for (i = 0; i < ptr->code_end - 1; i ++)
+ if (ptr->code[i] == push_text
+ && ptr->code[i + 1])
+ {
+ free ((char *) ptr->code[i + 1] - 1);
+ ++ i;
+ }
+ free (ptr->code);
+ }
+ next = ptr->next;
+ free (ptr);
+ ptr = next;
+ }
+}
+
+static void
+perform (void)
{
tos = stack;
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;
char *name;
void (*func) ();
{
- dict_type *new_d = newentry (name);
+ dict_type *new_d = newentry (strdup (name));
add_to_definition (new_d, func);
add_to_definition (new_d, 0);
}
{
/* Add words to the dictionary. */
char *word;
+
string = nextword (string, &word);
while (string && *string && word[0])
{
if (strcmp (word, "var") == 0)
{
+ free (word);
string = nextword (string, &word);
-
+ if (!string)
+ continue;
add_var (word);
string = nextword (string, &word);
}
else if (word[0] == ':')
{
dict_type *ptr;
+
/* 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] != ';')
{
switch (word[0])
function */
add_to_definition (ptr, push_number);
add_to_definition (ptr, (stinst_type) atol (word));
+ free (word);
break;
default:
add_to_definition (ptr, call);
add_to_definition (ptr, (stinst_type) lookup_word (word));
+ free (word);
}
string = nextword (string, &word);
}
add_to_definition (ptr, 0);
+ free (word);
string = nextword (string, &word);
}
else
fprintf (stderr, "syntax error at %s\n", string - 1);
}
}
+ if (word)
+ free (word);
}
static void
read_in (&b, f);
compile (b.ptr);
perform ();
+ delete_string (&b);
}
else if (av[i][1] == 'i')
{
}
}
write_buffer (stack + 0, stdout);
+ free_words ();
+ delete_string (&pptr);
+ delete_string (&buffer);
if (tos != stack)
{
fprintf (stderr, "finishing with current stack level %ld\n",