shithub: scc

Download patch

ref: 69fd68486ad58e08c0c2ffbff258f4dff50688fa
parent: 7d3fad26e7ad46f02234d9854473a0d93b3310c6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Feb 12 11:51:31 EST 2017

[cc2-qbe] Fix writeout() without a function

Writeout() uses the curfun pointer without checking
if we have a function. This generates a segmentation
fault in this input:

	struct S { unsigned int a; };

--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -340,6 +340,8 @@
 	char *sep, *name;
 	int haslabel = 0;
 
+	if (!curfun)
+		return;
 	if (curfun->kind == SGLOB)
 		fputs("export ", stdout);
 	printf("function %s %s(", size2stack(&curfun->rtype), symname(curfun));