From: Florian Forster Date: Wed, 7 Feb 2007 11:33:17 +0000 (+0100) Subject: parser.y: Fix segfaults due to wrong allocation size. X-Git-Tag: liboconfig-0.1.0~10 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=042ec8b4b5b7cabc9ff8833faab7fc9e6ce8b0f3;p=liboconfig.git parser.y: Fix segfaults due to wrong allocation size. --- diff --git a/src/parser.y b/src/parser.y index 911363c..a4ebce0 100644 --- a/src/parser.y +++ b/src/parser.y @@ -3,15 +3,6 @@ #include #include "oconfig.h" -static oconfig_item_t *ci_root; -static oconfig_item_t *ci_current; - -static oconfig_item_t *statement_list; -static int statement_list_num; - -static oconfig_value_t *argument_list; -static int argument_list_num; - struct statement_list_s { oconfig_item_t *statement; @@ -36,7 +27,6 @@ static void dump_ci (oconfig_item_t *ci, int shift); int boolean; char *string; oconfig_value_t cv; - oconfig_value_t *cvp; oconfig_item_t ci; argument_list_t al; statement_list_t sl; @@ -49,11 +39,14 @@ static void dump_ci (oconfig_item_t *ci, int shift); %type string %type identifier -%type block_end +/* arguments */ %type argument %type argument_list +/* blocks */ %type block_begin %type block +%type block_end +/* statements */ %type option %type statement %type statement_list @@ -76,12 +69,12 @@ argument_list: { $$ = $1; $$.argument_num++; - $$.argument = realloc ($$.argument, $$.argument_num * sizeof (argument_list_t)); + $$.argument = realloc ($$.argument, $$.argument_num * sizeof (oconfig_value_t)); $$.argument[$$.argument_num-1] = $2; } | argument { - $$.argument = malloc (sizeof (argument_list_t)); + $$.argument = malloc (sizeof (oconfig_value_t)); $$.argument[0] = $1; $$.argument_num = 1; } @@ -98,7 +91,6 @@ option: $$.key = $1; $$.values = $2.argument; $$.values_num = $2.argument_num; - printf ("Option `%s' has %i arguments\n", $$.key, $$.values_num); } ; @@ -109,12 +101,14 @@ block_begin: $$.key = $2; $$.values = $3.argument; $$.values_num = $3.argument_num; - printf ("Begin block `%s'\n", $2); } ; block_end: - OPENBRAC SLASH identifier CLOSEBRAC EOL {$$ = $3; printf ("End block `%s'\n", $3);} + OPENBRAC SLASH identifier CLOSEBRAC EOL + { + $$ = $3; + } ; block: @@ -124,6 +118,7 @@ block: yyerror ("Block %s not closed..\n", $1); $$ = $1; $$.children = $2.statement; + $$.children_num = $2.statement_num; } ; @@ -138,13 +133,12 @@ statement_list: { $$ = $1; $$.statement_num++; - $$.statement = realloc ($$.statement, $$.statement_num * sizeof (statement_list_t)); + $$.statement = realloc ($$.statement, $$.statement_num * sizeof (oconfig_item_t)); $$.statement[$$.statement_num-1] = $2; - printf ("statement_list: length = %i\n", $$.statement_num); } | statement { - $$.statement = malloc (sizeof (statement_list_t)); + $$.statement = malloc (sizeof (oconfig_item_t)); $$.statement[0] = $1; $$.statement_num = 1; } @@ -185,7 +179,7 @@ static void dump_ci (oconfig_item_t *ci, int shift) int i; if (shift > 0) - printf ("%*s", "", shift); + printf ("%*s", shift, ""); printf ("%s", ci->key); for (i = 0; i < ci->values_num; i++)