shithub: scc

Download patch

ref: 184510ee208d5f05b4f472d9ce295ecff044861d
parent: f1dec280f4eb0f7b7fd8ee90fc70b1cecebd0c47
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 10 18:31:13 EDT 2014

Check correctness of endf functions in cc2

These commit enforces the check that when the file finishs
then the code is not inside some function.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -363,6 +363,8 @@
 static void
 endfunction(char *token)
 {
+	if (!curfun)
+		error(ESYNTAX);
 	listp = NULL;
 	genstack(curfun);
 	genaddable(listexp);
@@ -487,7 +489,8 @@
 found_eof:
 	if (ferror(stdin))
 		error(EFERROR, strerror(errno));
-	return;
+	if (!curfun)
+		return;
 
 syntax_error:
 	error(ESYNTAX);