Skip to contentSkip to conversation

Fix core dump on anonymous symbol.

PATCH In review Christopher Li 2 participants 2 messages Feb 10, 2007 – Feb 23, 2007 Sparse checker

lore
Share & tools
lore

Christopher Li

author maintainer
#0 lore raw

PATCH 1/1 Fix core dump on anonymous symbol.

Using the following can generate anonymous symbol without initializer expression.

	return (struct foo) {};

It would be nice if sparse does not crash on it.

linearize.c +10 -8
Index: sparse/linearize.c
===================================================================
@@ -116,14 +116,16 @@ const char *show_pseudo(pseudo_t pseudo)
 		}
 		expr = sym->initializer;
 		snprintf(buf, 64, "<anon symbol:%p>", sym);
-		switch (expr->type) {
-		case EXPR_VALUE:
-			snprintf(buf, 64, "<symbol value: %lld>", expr->value);
-			break;
-		case EXPR_STRING:
-			return show_string(expr->string);
-		default:
-			break;
+		if (expr) {
+			switch (expr->type) {
+			case EXPR_VALUE:
+				snprintf(buf, 64, "<symbol value: %lld>", expr->value);
+				break;
+			case EXPR_STRING:
+				return show_string(expr->string);
+			default:
+				break;
+			}
 		}
 		break;
 	}
#1 lore raw
Quoted 8 lines · Christopher Li

Using the following can generate anonymous symbol without initializer expression.

	return (struct foo) {};

It would be nice if sparse does not crash on it.

I tried several variants of the code you suggest, but I couldn't seem to reproduce the problem this solves. Could you supply a full .c file for a test case?

In any case, applied.

- Josh Triplett