Commit bed481d6 authored by Russ Cox's avatar Russ Cox

cmd/gc: correct errors in constant parsing

Change-Id: I36f77e7ac7f727d8f3b51133f4b3ef93c35b09f6
Reviewed-on: https://go-review.googlesource.com/4640Reviewed-by: default avatarAustin Clements <austin@google.com>
parent be4ecd98
...@@ -334,18 +334,23 @@ mpatoflt(Mpflt *a, char *as) ...@@ -334,18 +334,23 @@ mpatoflt(Mpflt *a, char *as)
break; break;
} }
} }
if(start == nil) if(start == nil) {
yyerror("malformed hex constant: %s", as);
goto bad; goto bad;
}
mphextofix(&a->val, start, s-start); mphextofix(&a->val, start, s-start);
if(a->val.ovf) if(a->val.ovf) {
yyerror("constant too large: %s", as);
goto bad; goto bad;
}
a->exp = 0; a->exp = 0;
mpnorm(a); mpnorm(a);
} }
for(;;) { for(;;) {
switch(c = *s++) { switch(c = *s++) {
default: default:
yyerror("malformed constant: %s (at %c)", as, c);
goto bad; goto bad;
case '-': case '-':
...@@ -357,8 +362,10 @@ mpatoflt(Mpflt *a, char *as) ...@@ -357,8 +362,10 @@ mpatoflt(Mpflt *a, char *as)
continue; continue;
case '.': case '.':
if(base == 16) if(base == 16) {
yyerror("decimal point in hex constant: %s", as);
goto bad; goto bad;
}
dp = 1; dp = 1;
continue; continue;
...@@ -414,8 +421,10 @@ mpatoflt(Mpflt *a, char *as) ...@@ -414,8 +421,10 @@ mpatoflt(Mpflt *a, char *as)
} }
if(eb) { if(eb) {
if(dp) if(dp) {
yyerror("decimal point and binary point in constant: %s", as);
goto bad; goto bad;
}
mpsetexp(a, a->exp+ex); mpsetexp(a, a->exp+ex);
goto out; goto out;
} }
...@@ -444,7 +453,6 @@ out: ...@@ -444,7 +453,6 @@ out:
return; return;
bad: bad:
yyerror("constant too large: %s", as);
mpmovecflt(a, 0.0); mpmovecflt(a, 0.0);
} }
...@@ -483,6 +491,7 @@ mpatofix(Mpint *a, char *as) ...@@ -483,6 +491,7 @@ mpatofix(Mpint *a, char *as)
c = *s++; c = *s++;
continue; continue;
} }
yyerror("malformed decimal constant: %s", as);
goto bad; goto bad;
} }
goto out; goto out;
...@@ -498,6 +507,7 @@ oct: ...@@ -498,6 +507,7 @@ oct:
c = *s++; c = *s++;
continue; continue;
} }
yyerror("malformed octal constant: %s", as);
goto bad; goto bad;
} }
goto out; goto out;
...@@ -511,11 +521,14 @@ hex: ...@@ -511,11 +521,14 @@ hex:
c = *s; c = *s;
continue; continue;
} }
yyerror("malformed hex constant: %s", as);
goto bad; goto bad;
} }
mphextofix(a, s0, s-s0); mphextofix(a, s0, s-s0);
if(a->ovf) if(a->ovf) {
yyerror("constant too large: %s", as);
goto bad; goto bad;
}
out: out:
if(f) if(f)
...@@ -523,7 +536,6 @@ out: ...@@ -523,7 +536,6 @@ out:
return; return;
bad: bad:
yyerror("constant too large: %s", as);
mpmovecfix(a, 0); mpmovecfix(a, 0);
} }
......
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