From 4c71083b074b5af0493d540bf8b971b2dc07311a Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 30 Sep 2019 13:26:59 -0400 Subject: Fix func_info members initialized after malloc --- pc.l | 4 ++++ pc.y | 3 +++ 2 files changed, 7 insertions(+) diff --git a/pc.l b/pc.l index a8cde6c..229b763 100644 --- a/pc.l +++ b/pc.l @@ -3,6 +3,7 @@ #include "scope.h" #include "y.tab.h" #include "pc.h" +#include "assert.h" int line_num=1; extern scope *cur_scope; @@ -38,6 +39,9 @@ input { node *tmp; tmp = scope_insert(cur_scope, strdup("write")); tmp->func_info = malloc(sizeof(struct fi)); + assert(tmp->func_info); + tmp->func_info->argc = -1; + tmp->func_info->argv = NULL; return IO; } diff --git a/pc.y b/pc.y index 1ada604..4c4b276 100644 --- a/pc.y +++ b/pc.y @@ -219,6 +219,7 @@ sub_prog_head tmp->func_info = malloc(sizeof(struct fi)); assert(tmp->func_info); + tmp->func_info->argv = NULL; tmp->func_info->argc = i; assert(tmp->func_info->argv = malloc(i * sizeof(int))); @@ -247,7 +248,9 @@ sub_prog_head tmp->func_info = malloc(sizeof(struct fi)); assert(tmp->func_info); + tmp->func_info->argv = NULL; tmp->func_info->argc = i; + assert(tmp->func_info->argv = malloc(i * sizeof(int))); assert(!set_func_types($3, tmp->func_info->argv, i)); -- cgit v1.1