X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fliboconfig%2Fparser.y;h=04941073a168c70b9504a30e60ac55c5046233f9;hb=c9d3f76a5bd7aaa3d8772e88f8c0292e8b55f66b;hp=803eec26205317b30c21425c9c2821a4f75321fe;hpb=b66d5b90a0e59e943a61acb4b68ce55e88f08ade;p=collectd.git diff --git a/src/liboconfig/parser.y b/src/liboconfig/parser.y index 803eec26..04941073 100644 --- a/src/liboconfig/parser.y +++ b/src/liboconfig/parser.y @@ -94,13 +94,23 @@ argument_list: argument_list argument { $$ = $1; + oconfig_value_t *tmp = realloc($$.argument, + ($$.argument_num+1) * sizeof(*$$.argument)); + if (tmp == NULL) { + yyerror("realloc failed"); + YYERROR; + } + $$.argument = tmp; + $$.argument[$$.argument_num] = $2; $$.argument_num++; - $$.argument = realloc ($$.argument, $$.argument_num * sizeof (oconfig_value_t)); - $$.argument[$$.argument_num-1] = $2; } | argument { - $$.argument = malloc (sizeof (oconfig_value_t)); + $$.argument = calloc(1, sizeof(*$$.argument)); + if ($$.argument == NULL) { + yyerror("calloc failed"); + YYERROR; + } $$.argument[0] = $1; $$.argument_num = 1; } @@ -184,16 +194,26 @@ statement_list: $$ = $1; if (($2.values_num > 0) || ($2.children_num > 0)) { + oconfig_item_t *tmp = realloc($$.statement, + ($$.statement_num+1) * sizeof(*tmp)); + if (tmp == NULL) { + yyerror("realloc failed"); + YYERROR; + } + $$.statement = tmp; + $$.statement[$$.statement_num] = $2; $$.statement_num++; - $$.statement = realloc ($$.statement, $$.statement_num * sizeof (oconfig_item_t)); - $$.statement[$$.statement_num-1] = $2; } } | statement { if (($1.values_num > 0) || ($1.children_num > 0)) { - $$.statement = malloc (sizeof (oconfig_item_t)); + $$.statement = calloc(1, sizeof(*$$.statement)); + if ($$.statement == NULL) { + yyerror("calloc failed"); + YYERROR; + } $$.statement[0] = $1; $$.statement_num = 1; } @@ -208,17 +228,21 @@ statement_list: entire_file: statement_list { - ci_root = malloc (sizeof (oconfig_item_t)); - memset (ci_root, '\0', sizeof (oconfig_item_t)); + ci_root = calloc(1, sizeof(*ci_root)); + if (ci_root == NULL) { + yyerror("calloc failed"); + YYERROR; + } ci_root->children = $1.statement; ci_root->children_num = $1.statement_num; } | /* epsilon */ { - ci_root = malloc (sizeof (oconfig_item_t)); - memset (ci_root, '\0', sizeof (oconfig_item_t)); - ci_root->children = NULL; - ci_root->children_num = 0; + ci_root = calloc(1, sizeof(*ci_root)); + if (ci_root == NULL) { + yyerror("calloc failed"); + YYERROR; + } } ; @@ -241,7 +265,6 @@ static char *unquote (const char *orig) { char *ret = strdup (orig); int len; - int i; if (ret == NULL) return (NULL); @@ -255,7 +278,7 @@ static char *unquote (const char *orig) memmove (ret, ret + 1, len); ret[len] = '\0'; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { if (ret[i] == '\\') {