From: erikb Date: Tue, 2 Sep 1986 15:22:54 +0000 (+0000) Subject: various null-dereference problems fixed X-Git-Tag: release-5-5~5235 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5927f264a81b3e8ed0232d3cf3d54aba6345561c;p=ack.git various null-dereference problems fixed --- diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index b56e16e32..c273ba359 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -183,7 +183,12 @@ begin_proc(name, def) /* to be called when entering a procedure */ DfaStartFunction(name); #endif DATAFLOW - func_tp = def->df_type->tp_up; + if (def->df_type->tp_fund != FUNCTION) { + error("making function body for non-function"); + func_tp = error_type; + } + else + func_tp = def->df_type->tp_up; size = ATW(func_tp->tp_size); C_pro_narg(name); if (is_struct_or_union(func_tp->tp_fund)) { diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 3549c8406..4fa8cf7e1 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -171,6 +171,7 @@ idf2expr(expr) /* now def != 0 */ if (def->df_type->tp_fund == LABEL) { expr_error(expr, "illegal use of label %s", idf->id_text); + expr->ex_type = error_type; } else { def->df_used = 1; diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 05e74f8b0..aa6c48f1b 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -181,7 +181,7 @@ declare_idf(ds, dc, lvl) /* at the L_FORMAL1 level there is no type specified yet */ ASSERT(lvl == L_FORMAL1); - type = 0; + type = int_type; /* may change at L_FORMAL2 */ } else { /* combine the decspecs and the declarator into one type */ @@ -583,7 +583,7 @@ declare_parameter(idf) { /* idf is declared as a formal. */ - add_def(idf, FORMAL, (struct type *)0, level); + add_def(idf, FORMAL, int_type, level); } declare_enum(tp, idf, l) @@ -616,8 +616,6 @@ declare_formals(fp) struct idf *idf = se->se_idf; struct def *def = idf->id_def; - if (def->df_type == 0) - def->df_type = int_type; /* default type */ def->df_address = f_offset; /* the alignment convention for parameters is: align on diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index 62ce1b3a2..4109ba07e 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -279,7 +279,7 @@ switch_statement '(' expression(&expr) { - code_startswitch(expr); + code_startswitch(&expr); } ')' statement diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index b7e266e63..b5af15c0e 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -310,7 +310,7 @@ idf2sdef(idf, tp) *sdefp = sdef = new_sdef(); clear((char *)sdef, sizeof(struct sdef)); sdef->sd_idf = idf; - sdef->sd_type = error_type; + sdef->sd_stype = sdef->sd_type = error_type; return sdef; } diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 30fd0abea..4a73673cd 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -32,8 +32,8 @@ static struct switch_hdr *switch_stack = 0; For simplicity, we suppose int_size == word_size. */ -code_startswitch(expr) - struct expr *expr; +code_startswitch(expp) + struct expr **expp; { /* Check the expression, stack a new case header and fill in the necessary fields. @@ -41,17 +41,17 @@ code_startswitch(expr) register label l_table = text_label(); register label l_break = text_label(); register struct switch_hdr *sh = new_switch_hdr(); - int fund = any2arith(&expr, SWITCH); /* INT, LONG or DOUBLE */ + int fund = any2arith(expp, SWITCH); /* INT, LONG or DOUBLE */ switch (fund) { case LONG: if (options['R']) warning("long in switch (cast to int)"); - int2int(&expr, int_type); + int2int(expp, int_type); break; case DOUBLE: error("float/double in switch"); - erroneous2int(&expr); + erroneous2int(expp); break; } @@ -60,12 +60,12 @@ code_startswitch(expr) sh->sh_default = 0; sh->sh_table = l_table; sh->sh_nrofentries = 0; - sh->sh_type = expr->ex_type; /* the expression switched */ + sh->sh_type = (*expp)->ex_type; /* the expression switched */ sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* immaterial ??? */ sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ sh->next = switch_stack; /* push onto switch-stack */ switch_stack = sh; - code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + code_expr(*expp, RVAL, TRUE, NO_LABEL, NO_LABEL); /* evaluate the switch expr. */ C_bra(l_table); /* goto start of switch_table */ }