shithub: scc

Download patch

ref: 2346a6274196c02e801c7bb1dfab68332ce1e766
parent: 493d1fe087d5b30f9a74b6e51697e10ea6fc9ad8
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jun 22 07:18:47 EDT 2016

[cc1] Do not allow comments between different files

C89 says: 'A source file shall not end in a partial
preprocessing token or comment', and C99 says:
Must a comment be contained within one #include file? (Yes.).
In the case of C99, otherwise is an UB. We think the best
option here is giving an error.

--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -167,16 +167,17 @@
 repeat:
 	do {
 		if (!c)
-			delinput();
+			goto unterminated;
 	} while (!eof && (c = readchar()) != type);
 
-	if (eof) {
-		errorp("unterminated comment");
-		return;
-	}
-
+	if (eof)
+		goto unterminated;
 	if (type == '*' && (c = readchar()) != '/')
 		goto repeat;
+	return;
+
+unterminated:
+	errorp("unterminated comment");
 }
 
 static int
--- a/cc1/tests/test063.c
+++ b/cc1/tests/test063.c
@@ -4,7 +4,7 @@
 name: TEST063
 description: Test a comment that goes beyond of the end of an included file
 error:
-test063.c:12: error: unterminated comment
+test063.h:9: error: unterminated comment
 test063.c:12: error: #endif expected
 output:
 */