diff options
author | Anders Magnusson <ragge@cvs.openbsd.org> | 2007-10-27 12:50:51 +0000 |
---|---|---|
committer | Anders Magnusson <ragge@cvs.openbsd.org> | 2007-10-27 12:50:51 +0000 |
commit | 7cfc9671208f2485a956b50997e97f4765088107 (patch) | |
tree | 18e3e2e10b091598671c61efc62e2dfa197ad43b /usr.bin | |
parent | 6b1781633089139afc3a7f4b66d0d59434086247 (diff) |
Pull up changes from master repo:
> Fix preprocessor number overflow check, by Jan Kryl.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/pcc/cpp/cpp.1 | 6 | ||||
-rw-r--r-- | usr.bin/pcc/cpp/cpp.c | 8 | ||||
-rw-r--r-- | usr.bin/pcc/cpp/scanner.l | 20 |
3 files changed, 21 insertions, 13 deletions
diff --git a/usr.bin/pcc/cpp/cpp.1 b/usr.bin/pcc/cpp/cpp.1 index 31ddb32db51..dcba1e3a99e 100644 --- a/usr.bin/pcc/cpp/cpp.1 +++ b/usr.bin/pcc/cpp/cpp.1 @@ -1,6 +1,6 @@ -.\" $Id: cpp.1,v 1.1 2007/10/07 17:58:51 otto Exp $ +.\" $Id: cpp.1,v 1.2 2007/10/27 12:50:50 ragge Exp $ .\" $NetBSD$ -.\" $OpenBSD: cpp.1,v 1.1 2007/10/07 17:58:51 otto Exp $ +.\" $OpenBSD: cpp.1,v 1.2 2007/10/27 12:50:50 ragge Exp $ ."\ .\" Copyright (c) 2007 Jeremy C. Reed <reed@reedmedia.net> .\" @@ -26,7 +26,7 @@ .Sh SYNOPSIS .Nm .\" TODO also document -Dvar and below without spaces? -.Op Fl CdMt +.Op Fl CdMtVv .Op Fl D Ar macro[=value] .Op Fl I Ar path .Op Fl i Ar file diff --git a/usr.bin/pcc/cpp/cpp.c b/usr.bin/pcc/cpp/cpp.c index 8e35c230c43..db7b94c5964 100644 --- a/usr.bin/pcc/cpp/cpp.c +++ b/usr.bin/pcc/cpp/cpp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpp.c,v 1.5 2007/10/22 17:49:01 otto Exp $ */ +/* $OpenBSD: cpp.c,v 1.6 2007/10/27 12:50:50 ragge Exp $ */ /* * Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se). @@ -173,7 +173,7 @@ main(int argc, char **argv) struct symtab *nl; register int ch; - while ((ch = getopt(argc, argv, "CD:I:MS:U:d:i:tvV")) != -1) + while ((ch = getopt(argc, argv, "CD:I:MS:U:d:i:tvV?")) != -1) switch (ch) { case 'C': /* Do not discard comments */ Cflag++; @@ -431,7 +431,7 @@ line() yytext[strlen(yytext)-1] = 0; if (strlcpy((char *)lbuf, &yytext[1], SBSIZE) >= SBSIZE) error("line exceeded buffer size"); - + ifiles->fname = lbuf; if (yylex() != '\n') goto bad; @@ -752,7 +752,7 @@ xerror(usch *s) flbuf(); savch(0); if (ifiles != NULL) { - t = sheap("%s:%d: ", ifiles->fname, ifiles->lineno); + t = sheap("%s:%d: error: ", ifiles->fname, ifiles->lineno); write (2, t, strlen((char *)t)); } write (2, s, strlen((char *)s)); diff --git a/usr.bin/pcc/cpp/scanner.l b/usr.bin/pcc/cpp/scanner.l index 5deea79eff1..035127fb0fb 100644 --- a/usr.bin/pcc/cpp/scanner.l +++ b/usr.bin/pcc/cpp/scanner.l @@ -1,5 +1,5 @@ %{ -/* $Id: scanner.l,v 1.3 2007/10/21 18:58:02 otto Exp $ */ +/* $Id: scanner.l,v 1.4 2007/10/27 12:50:50 ragge Exp $ */ /* * Copyright (c) 2004 Anders Magnusson. All rights reserved. @@ -490,12 +490,13 @@ dig2num(int c) } /* - * Convert some string numbers to long long. + * Convert string numbers to unsigned long long and check overflow. */ -void +static void cvtdig(int rad) { - long long rv = 0; + unsigned long long rv = 0; + unsigned long long rv2 = 0; char *y = yytext; int c; @@ -504,13 +505,20 @@ cvtdig(int rad) y++; while (isxdigit(c)) { rv = rv * rad + dig2num(c); + /* check overflow */ + if (rv / rad < rv2) + error("Constant \"%s\" is out of range", yytext); + rv2 = rv; c = *y++; } y--; while (*y == 'l' || *y == 'L') y++; yylval.node.op = *y == 'u' || *y == 'U' ? UNUMBER : NUMBER; - yylval.node.nd_val = rv; + yylval.node.nd_uval = rv; + if (yylval.node.op == NUMBER && yylval.node.nd_val < 0) + /* too large for signed */ + error("Constant \"%s\" is out of range", yytext); } static int @@ -784,7 +792,7 @@ cpperror(void) if (flslvl) stringbuf = cp; else - error("error: %s", cp); + error("%s", cp); } static void |