comparison place.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
comparison
equal deleted inserted replaced
202:e200cb46ab23 203:3a25180d3a5c
191 p->file = pf; 191 p->file = pf;
192 p->line = 1; 192 p->line = 1;
193 p->column = 1; 193 p->column = 1;
194 } 194 }
195 195
196 void
197 place_addcolumns(struct place *p, unsigned cols)
198 {
199 unsigned newcol;
200
201 newcol = p->column + cols;
202 if (newcol < p->column) {
203 /* overflow (use the old place to complain) */
204 complain(p, "Column numbering overflow");
205 die();
206 }
207 p->column = newcol;
208 }
209
210 void
211 place_addlines(struct place *p, unsigned lines)
212 {
213 unsigned nextline;
214
215 nextline = p->line + lines;
216 if (nextline < p->line) {
217 /* overflow (use the old place to complain) */
218 complain(p, "Line numbering overflow");
219 die();
220 }
221 p->line = nextline;
222 }
223
196 const char * 224 const char *
197 place_getname(const struct place *p) 225 place_getname(const struct place *p)
198 { 226 {
199 switch (p->type) { 227 switch (p->type) {
200 case P_NOWHERE: return "<nowhere>"; 228 case P_NOWHERE: return "<nowhere>";