Commit 0decedf6 authored by Russ Cox's avatar Russ Cox

gc: various bug fixes

Fixes #935.
Fixes #936.
Fixes #941.

R=ken2
CC=golang-dev
https://golang.org/cl/1867042
parent de228c0e
...@@ -26,9 +26,44 @@ static int32 getr(void); ...@@ -26,9 +26,44 @@ static int32 getr(void);
static int escchar(int, int*, vlong*); static int escchar(int, int*, vlong*);
static void addidir(char*); static void addidir(char*);
static int getlinepragma(void); static int getlinepragma(void);
static char *goos, *goarch, *goroot; static char *goos, *goarch, *goroot;
// Our own isdigit, isspace, isalpha, isalnum that take care
// of EOF and other out of range arguments.
static int
yy_isdigit(int c)
{
return c >= 0 && c <= 0xFF && isdigit(c);
}
static int
yy_isspace(int c)
{
return c >= 0 && c <= 0xFF && isspace(c);
}
static int
yy_isalpha(int c)
{
return c >= 0 && c <= 0xFF && isalpha(c);
}
static int
yy_isalnum(int c)
{
return c >= 0 && c <= 0xFF && isalnum(c);
}
// Disallow use of isdigit etc.
#undef isdigit
#undef isspace
#undef isalpha
#undef isalnum
#define isdigit use_yy_isdigit_instead_of_isdigit
#define isspace use_yy_isspace_instead_of_isspace
#define isalpha use_yy_isalpha_instead_of_isalpha
#define isalnum use_yy_isalnum_instead_of_isalnum
#define DBG if(!debug['x']);else print #define DBG if(!debug['x']);else print
enum enum
{ {
...@@ -122,7 +157,7 @@ main(int argc, char *argv[]) ...@@ -122,7 +157,7 @@ main(int argc, char *argv[])
if(getwd(pathname, 999) == 0) if(getwd(pathname, 999) == 0)
strcpy(pathname, "/???"); strcpy(pathname, "/???");
if(isalpha(pathname[0]) && pathname[1] == ':') { if(yy_isalpha(pathname[0]) && pathname[1] == ':') {
// On Windows. // On Windows.
windows = 1; windows = 1;
...@@ -290,7 +325,7 @@ islocalname(Strlit *name) ...@@ -290,7 +325,7 @@ islocalname(Strlit *name)
if(!windows && name->len >= 1 && name->s[0] == '/') if(!windows && name->len >= 1 && name->s[0] == '/')
return 1; return 1;
if(windows && name->len >= 3 && if(windows && name->len >= 3 &&
isalpha(name->s[0]) && name->s[1] == ':' && name->s[2] == '/') yy_isalpha(name->s[0]) && name->s[1] == ':' && name->s[2] == '/')
return 1; return 1;
if(name->len >= 2 && strncmp(name->s, "./", 2) == 0) if(name->len >= 2 && strncmp(name->s, "./", 2) == 0)
return 1; return 1;
...@@ -499,7 +534,7 @@ _yylex(void) ...@@ -499,7 +534,7 @@ _yylex(void)
l0: l0:
c = getc(); c = getc();
if(isspace(c)) { if(yy_isspace(c)) {
if(c == '\n' && curio.nlsemi) { if(c == '\n' && curio.nlsemi) {
ungetc(c); ungetc(c);
DBG("lex: implicit semi\n"); DBG("lex: implicit semi\n");
...@@ -517,13 +552,13 @@ l0: ...@@ -517,13 +552,13 @@ l0:
goto talph; goto talph;
} }
if(isalpha(c)) { if(yy_isalpha(c)) {
cp = lexbuf; cp = lexbuf;
ep = lexbuf+sizeof lexbuf; ep = lexbuf+sizeof lexbuf;
goto talph; goto talph;
} }
if(isdigit(c)) if(yy_isdigit(c))
goto tnum; goto tnum;
switch(c) { switch(c) {
...@@ -539,7 +574,7 @@ l0: ...@@ -539,7 +574,7 @@ l0:
case '.': case '.':
c1 = getc(); c1 = getc();
if(isdigit(c1)) { if(yy_isdigit(c1)) {
cp = lexbuf; cp = lexbuf;
ep = lexbuf+sizeof lexbuf; ep = lexbuf+sizeof lexbuf;
*cp++ = c; *cp++ = c;
...@@ -906,7 +941,7 @@ talph: ...@@ -906,7 +941,7 @@ talph:
if(!isalpharune(rune) && !isdigitrune(rune) && (importpkg == nil || rune != 0xb7)) if(!isalpharune(rune) && !isdigitrune(rune) && (importpkg == nil || rune != 0xb7))
yyerror("invalid identifier character 0x%ux", rune); yyerror("invalid identifier character 0x%ux", rune);
cp += runetochar(cp, &rune); cp += runetochar(cp, &rune);
} else if(!isalnum(c) && c != '_') } else if(!yy_isalnum(c) && c != '_')
break; break;
else else
*cp++ = c; *cp++ = c;
...@@ -944,7 +979,7 @@ tnum: ...@@ -944,7 +979,7 @@ tnum:
} }
*cp++ = c; *cp++ = c;
c = getc(); c = getc();
if(isdigit(c)) if(yy_isdigit(c))
continue; continue;
goto dc; goto dc;
} }
...@@ -959,7 +994,7 @@ tnum: ...@@ -959,7 +994,7 @@ tnum:
} }
*cp++ = c; *cp++ = c;
c = getc(); c = getc();
if(isdigit(c)) if(yy_isdigit(c))
continue; continue;
if(c >= 'a' && c <= 'f') if(c >= 'a' && c <= 'f')
continue; continue;
...@@ -980,7 +1015,7 @@ tnum: ...@@ -980,7 +1015,7 @@ tnum:
yyerror("identifier too long"); yyerror("identifier too long");
errorexit(); errorexit();
} }
if(!isdigit(c)) if(!yy_isdigit(c))
break; break;
if(c < '0' || c > '7') if(c < '0' || c > '7')
c1 = 1; // not octal c1 = 1; // not octal
...@@ -1029,7 +1064,7 @@ casedot: ...@@ -1029,7 +1064,7 @@ casedot:
} }
*cp++ = c; *cp++ = c;
c = getc(); c = getc();
if(!isdigit(c)) if(!yy_isdigit(c))
break; break;
} }
if(c == 'i') if(c == 'i')
...@@ -1044,9 +1079,9 @@ casee: ...@@ -1044,9 +1079,9 @@ casee:
*cp++ = c; *cp++ = c;
c = getc(); c = getc();
} }
if(!isdigit(c)) if(!yy_isdigit(c))
yyerror("malformed fp constant exponent"); yyerror("malformed fp constant exponent");
while(isdigit(c)) { while(yy_isdigit(c)) {
if(cp+10 >= ep) { if(cp+10 >= ep) {
yyerror("identifier too long"); yyerror("identifier too long");
errorexit(); errorexit();
...@@ -1065,9 +1100,9 @@ casep: ...@@ -1065,9 +1100,9 @@ casep:
*cp++ = c; *cp++ = c;
c = getc(); c = getc();
} }
if(!isdigit(c)) if(!yy_isdigit(c))
yyerror("malformed fp constant exponent"); yyerror("malformed fp constant exponent");
while(isdigit(c)) { while(yy_isdigit(c)) {
if(cp+10 >= ep) { if(cp+10 >= ep) {
yyerror("identifier too long"); yyerror("identifier too long");
errorexit(); errorexit();
...@@ -1145,9 +1180,13 @@ getlinepragma(void) ...@@ -1145,9 +1180,13 @@ getlinepragma(void)
n = 0; n = 0;
for(;;) { for(;;) {
c = getr(); c = getr();
if(!isdigit(c)) if(!yy_isdigit(c))
break; break;
n = n*10 + (c-'0'); n = n*10 + (c-'0');
if(n > 1e8) {
yyerror("line number out of range");
errorexit();
}
} }
if(c != '\n' || n <= 0) if(c != '\n' || n <= 0)
......
...@@ -218,6 +218,8 @@ static double tab[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 }; ...@@ -218,6 +218,8 @@ static double tab[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 };
static void static void
mppow10flt(Mpflt *a, int p) mppow10flt(Mpflt *a, int p)
{ {
if(p < 0)
abort();
if(p < nelem(tab)) { if(p < nelem(tab)) {
mpmovecflt(a, tab[p]); mpmovecflt(a, tab[p]);
return; return;
...@@ -297,6 +299,10 @@ mpatoflt(Mpflt *a, char *as) ...@@ -297,6 +299,10 @@ mpatoflt(Mpflt *a, char *as)
} }
if(c >= '0' && c <= '9') { if(c >= '0' && c <= '9') {
ex = ex*10 + (c-'0'); ex = ex*10 + (c-'0');
if(ex > 1e8) {
yyerror("exponent out of range");
errorexit();
}
continue; continue;
} }
break; break;
......
...@@ -154,6 +154,10 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -154,6 +154,10 @@ exprfmt(Fmt *f, Node *n, int prec)
break; break;
case OTYPE: case OTYPE:
if(n->type == T && n->sym != S) {
fmtprint(f, "%S", n->sym);
break;
}
fmtprint(f, "%T", n->type); fmtprint(f, "%T", n->type);
break; break;
......
...@@ -134,6 +134,10 @@ walkdeftype(Node *n) ...@@ -134,6 +134,10 @@ walkdeftype(Node *n)
n->diag = 1; n->diag = 1;
goto ret; goto ret;
} }
if(n->type == T) {
n->diag = 1;
goto ret;
}
// copy new type and clear fields // copy new type and clear fields
// that don't come along // that don't come along
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment