vnmakarov / yaep

Yet Another Earley Parser
Other
135 stars 13 forks source link

Some compiler warnings about possible uninitialized variables #29

Open mingodad opened 3 years ago

mingodad commented 3 years ago

Adding -Wall -Wextra with gcc give a few warnings and some of then I fixed as shown bellow:

diff --git a/src/yaep.c b/src/yaep.c
index 3719017..b68cce8 100644
--- a/src/yaep.c
+++ b/src/yaep.c
@@ -5263,8 +5263,8 @@ static vlo_t *tnodes_vlo;
 static struct yaep_tree_node *
 prune_to_minimal (struct yaep_tree_node *node, int *cost)
 {
-  struct yaep_tree_node *child, *alt, *next_alt, *result;
-  int i, min_cost;
+  struct yaep_tree_node *child, *alt, *next_alt, *result = NULL;
+  int i, min_cost = 0;

   assert (node != NULL);
   switch (node->type)
@@ -5431,7 +5431,7 @@ make_parse (int *ambiguous_p)
   struct yaep_tree_node *parent_anode, *anode, root_anode;
   int parent_disp;
   int saved_one_parse_p;
-  struct yaep_tree_node **term_node_array;
+  struct yaep_tree_node **term_node_array = NULL;
 #ifndef __cplusplus
   vlo_t stack, orig_states;
 #else
@@ -6420,7 +6420,7 @@ read_rule (const char ***rhs, const char **anode, int *anode_cost,

 /* The following variable is the current number of next input
    token. */
-static int ntok;
+static size_t ntok;

 /* The following function imported by Earley's algorithm (see comments
    in the interface file). */