Fix segmentation fault when define global with location but no name (reported by brendan)
--- a/stage4/generate_c/generate_c_vardecl.cc Thu Jun 18 19:18:54 2009 +0200
+++ b/stage4/generate_c/generate_c_vardecl.cc Fri Jun 19 13:26:31 2009 +0200
@@ -1703,17 +1703,16 @@
// SYM_REF2(global_var_spec_c, global_var_name, location)
void *visit(global_var_spec_c *symbol) {
TRACE("global_var_spec_c");
-
/* now to produce the c equivalent... */
switch(wanted_varformat) {
case local_vf:
- s4o.print(s4o.indent_spaces);
+ s4o.print("extern ");
+ this->current_var_type_symbol->accept(*this);
+ s4o.print("* ");
+ symbol->location->accept(*this);
+ s4o.print(";\n");
if (symbol->global_var_name != NULL) {
- s4o.print("extern ");
- this->current_var_type_symbol->accept(*this);
- s4o.print("* ");
- symbol->location->accept(*this);
- s4o.print(";\n");
+ s4o.print(s4o.indent_spaces);
this->current_var_type_symbol->accept(*this);
s4o.print(" *");
if (this->resource_name != NULL) {
@@ -1723,6 +1722,7 @@
symbol->global_var_name->accept(*this);
s4o.print(";\n");
if (this->resource_name != NULL) {
+ s4o.print(s4o.indent_spaces);
s4o.print("#define ");
symbol->global_var_name->accept(*this);
s4o.print(" ");
--- a/stage4/generate_c/generate_var_list.cc Thu Jun 18 19:18:54 2009 +0200
+++ b/stage4/generate_c/generate_var_list.cc Fri Jun 19 13:26:31 2009 +0200
@@ -402,9 +402,10 @@
/*| global_var_name location */
// SYM_REF2(global_var_spec_c, global_var_name, location)
void *visit(global_var_spec_c *symbol) {
- if (symbol->global_var_name != NULL)
+ if (symbol->global_var_name != NULL) {
this->current_var_type_category = pointer_vtc;
declare_variable(symbol->global_var_name);
+ }
return NULL;
}