]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: correct errors in constant parsing
authorRuss Cox <rsc@golang.org>
Wed, 11 Feb 2015 04:49:26 +0000 (23:49 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 13 Feb 2015 17:30:14 +0000 (17:30 +0000)
Change-Id: I36f77e7ac7f727d8f3b51133f4b3ef93c35b09f6
Reviewed-on: https://go-review.googlesource.com/4640
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/gc/mparith1.c

index d33a81e09d7ee38094cdcd4505fd41cbd2a94135..d85dc73bd95aa194f455b5835bdf7c1d0d71a51d 100644 (file)
@@ -334,18 +334,23 @@ mpatoflt(Mpflt *a, char *as)
                                break;
                        }
                }
-               if(start == nil)
+               if(start == nil) {
+                       yyerror("malformed hex constant: %s", as);
                        goto bad;
+               }
 
                mphextofix(&a->val, start, s-start);
-               if(a->val.ovf)
+               if(a->val.ovf) {
+                       yyerror("constant too large: %s", as);
                        goto bad;
+               }
                a->exp = 0;
                mpnorm(a);
        }
        for(;;) {
                switch(c = *s++) {
                default:
+                       yyerror("malformed constant: %s (at %c)", as, c);
                        goto bad;
 
                case '-':
@@ -357,8 +362,10 @@ mpatoflt(Mpflt *a, char *as)
                        continue;
 
                case '.':
-                       if(base == 16)
+                       if(base == 16) {
+                               yyerror("decimal point in hex constant: %s", as);
                                goto bad;
+                       }
                        dp = 1;
                        continue;
 
@@ -414,8 +421,10 @@ mpatoflt(Mpflt *a, char *as)
        }
 
        if(eb) {
-               if(dp)
+               if(dp) {
+                       yyerror("decimal point and binary point in constant: %s", as);
                        goto bad;
+               }
                mpsetexp(a, a->exp+ex);
                goto out;
        }
@@ -444,7 +453,6 @@ out:
        return;
 
 bad:
-       yyerror("constant too large: %s", as);
        mpmovecflt(a, 0.0);
 }
 
@@ -483,6 +491,7 @@ mpatofix(Mpint *a, char *as)
                        c = *s++;
                        continue;
                }
+               yyerror("malformed decimal constant: %s", as);
                goto bad;
        }
        goto out;
@@ -498,6 +507,7 @@ oct:
                        c = *s++;
                        continue;
                }
+               yyerror("malformed octal constant: %s", as);
                goto bad;
        }
        goto out;
@@ -511,11 +521,14 @@ hex:
                        c = *s;
                        continue;
                }
+               yyerror("malformed hex constant: %s", as);
                goto bad;
        }
        mphextofix(a, s0, s-s0);
-       if(a->ovf)
+       if(a->ovf) {
+               yyerror("constant too large: %s", as);
                goto bad;
+       }
 
 out:
        if(f)
@@ -523,7 +536,6 @@ out:
        return;
 
 bad:
-       yyerror("constant too large: %s", as);
        mpmovecfix(a, 0);
 }