
mikhail at nessus
Oct 12, 2006, 4:25 AM
Views: 721
Permalink
|
|
libnasl/nasl nasl_var.c,1.61,1.62
|
|
Update of /usr/local/cvs/libnasl/nasl In directory raccoon.nessus.org:/tmp/cvs-serv35286/libnasl/nasl Modified Files: nasl_var.c Log Message: prints a warning if a global_variable is declared while a local variable with the same name already exists. Index: nasl_var.c =================================================================== RCS file: /usr/local/cvs/libnasl/nasl/nasl_var.c,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- nasl_var.c 4 Oct 2006 11:22:36 -0000 1.61 +++ nasl_var.c 12 Oct 2006 11:25:39 -0000 1.62 @@ -120,7 +120,7 @@ /* This function climbs up in the context list */ static named_nasl_var* -get_var_ref_by_name(lex_ctxt* ctxt, const char* name, int climb) +get_var_ref_by_name4(lex_ctxt* ctxt, const char* name, int climb, int create) { named_nasl_var *v, *prev; int h = hash_str(name); @@ -172,6 +172,8 @@ #endif } + if (! create) return NULL; + if (ctxt->ctx_vars.hash_elt == NULL) ctxt->ctx_vars.hash_elt = emalloc(sizeof(named_nasl_var*) * VAR_NAME_HASH); @@ -184,6 +186,11 @@ return v; } +static named_nasl_var* +get_var_ref_by_name(lex_ctxt* ctxt, const char* name, int climb) +{ + return get_var_ref_by_name4(ctxt, name, climb, 1); +} static anon_nasl_var* get_var_ref_by_num(lex_ctxt* ctxt, int num) @@ -864,19 +871,31 @@ return v; } -tree_cell* -decl_local_variables(lex_ctxt* lexic, tree_cell* vars) +static tree_cell* +decl_local_variables3(lex_ctxt* lexic, tree_cell* vars, lex_ctxt* upperctxt) { tree_cell *t; + lex_ctxt *c; for (t = vars; t != NULL; t = t->link[0]) if (t->x.str_val == NULL) nasl_perror(lexic, "decl_local_variables: null name!\n"); else - add_named_var_to_ctxt(lexic, t->x.str_val, NULL); + { + add_named_var_to_ctxt(lexic, t->x.str_val, NULL); + for (c = upperctxt; c != NULL && c != lexic; c= c->up_ctxt) + if (get_var_ref_by_name4(c, t->x.str_val, 0, 0) != NULL) + nasl_perror(lexic, "Variable '%s' will be shadowed by an inner context\n", t->x.str_val); + } return FAKE_CELL; } +tree_cell* +decl_local_variables(lex_ctxt* lexic, tree_cell* vars) +{ + decl_local_variables3(lexic, vars, NULL); +} + tree_cell* decl_global_variables(lex_ctxt* lexic, tree_cell* vars) { @@ -884,7 +903,7 @@ while (c->up_ctxt != NULL) c = c->up_ctxt; - return decl_local_variables(c, vars); + return decl_local_variables3(c, vars, lexic); } anon_nasl_var* _______________________________________________ Nessus-cvs mailing list Nessus-cvs [at] list http://mail.nessus.org/mailman/listinfo/nessus-cvs
|