diff directive.c @ 203:3a25180d3a5c

Abort on line numbering or column numbering overflow. Line numbers are limited to values that fit in "unsigned int". Also reject input lines longer than 2^32-1 characters. It seems reasonable to presume that any input that violates these constraints is someone screwing around and not a serious attempt to compile or preprocess anything useful. Done in response to n2129, but without getting into any of the silliness found there.
author David A. Holland
date Tue, 01 Aug 2017 14:51:04 -0400
parents 1d2bad7151f9
children
line wrap: on
line diff
--- a/directive.c	Thu Dec 15 23:53:13 2016 -0500
+++ b/directive.c	Tue Aug 01 14:51:04 2017 -0400
@@ -114,7 +114,7 @@
 
 	pos = strcspn(line, ws);
 	if (line[pos] != '\0') {
-		p2->column += pos;
+		place_addcolumns(p2, pos);
 		complain(p2, "Garbage after %s argument", what);
 		complain_fail();
 		line[pos] = '\0';
@@ -348,13 +348,13 @@
 		argpos = pos;
 		pos = pos + strcspn(line+pos, "()");
 		if (line[pos] == '(') {
-			p2->column += pos;
+			place_addcolumns(p2, pos);
 			complain(p2, "Left parenthesis in macro parameters");
 			complain_fail();
 			return;
 		}
 		if (line[pos] != ')') {
-			p2->column += pos;
+			place_addcolumns(p2, pos);
 			complain(p2, "Unclosed macro parameter list");
 			complain_fail();
 			return;
@@ -378,10 +378,10 @@
 	pos += strspn(line+pos, ws);
 
 	p3 = *p2;
-	p3.column += argpos;
+	place_addcolumns(&p3, argpos);
 
 	p4 = *p2;
-	p4.column += pos;
+	place_addcolumns(&p4, pos);
 
 	if (argpos) {
 		debuglog(&lp->current, "Defining %s()", line);
@@ -490,7 +490,8 @@
 	errno = 0;
 	val = strtoul(text, &moretext, 10);
 	if (errno) {
-		complain(&lp->current, "No line number in #line directive");
+		complain(&lp->current,
+			 "Invalid line number in #line directive");
 		goto fail;
 	}
 #if UINT_MAX < ULONG_MAX
@@ -502,7 +503,7 @@
 #endif
 	moretext += strspn(moretext, ws);
 	moretextlen = strlen(moretext);
-	lp->current.column += (moretext - text);
+	place_addcolumns(&lp->current, moretext - text);
 
 	if (moretextlen > 2 &&
 	    moretext[0] == '"' && moretext[moretextlen-1] == '"') {
@@ -610,7 +611,7 @@
 				return;
 			}
 			skip = len + strspn(line+len, ws);
-			p2.column += skip;
+			place_addcolumns(&p2, skip);
 			line += skip;
 
 			len = strlen(line);
@@ -667,10 +668,10 @@
 			pos++;
 		}
 		if (line[pos] == '\n') {
-			p2.line++;
+			place_addlines(&p2, 1);
 			p2.column = 0;
 		} else {
-			p2.column++;
+			place_addcolumns(&p2, 1);
 		}
 	}
 
@@ -692,13 +693,13 @@
 	if (len > 0 && line[0] == '#') {
 		skip = 1 + strspn(line + 1, ws);
 		assert(skip <= len);
-		lp->current.column += skip;
+		place_addcolumns(&lp->current, skip);
 		assert(line[len] == '\0');
 		directive_gotdirective(lp, line+skip /*, length = len-skip */);
-		lp->current.column += len-skip;
+		place_addcolumns(&lp->current, len-skip);
 	} else if (ifstate->curtrue) {
 		macro_sendline(&lp->current, line, len);
-		lp->current.column += len;
+		place_addcolumns(&lp->current, len);
 	}
 }