1
0
mirror of https://github.com/golang/go synced 2024-10-03 09:31:23 -06:00

cmd/gc: warn about slice indexes larger than int in typecheck pass

Fixes GOARCH=386 build.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6810098
This commit is contained in:
Ian Lance Taylor 2012-11-07 17:34:06 -08:00
parent 3e2a888753
commit e3977f0d3a

View File

@ -828,6 +828,10 @@ reswitch:
yyerror("invalid %s index %N (index must be non-negative)", why, n->right); yyerror("invalid %s index %N (index must be non-negative)", why, n->right);
} else if(isfixedarray(t) && t->bound > 0 && mpgetfix(n->right->val.u.xval) >= t->bound) } else if(isfixedarray(t) && t->bound > 0 && mpgetfix(n->right->val.u.xval) >= t->bound)
yyerror("invalid array index %N (out of bounds for %d-element array)", n->right, t->bound); yyerror("invalid array index %N (out of bounds for %d-element array)", n->right, t->bound);
else if(mpcmpfixfix(n->right->val.u.xval, maxintval[TINT]) > 0) {
why = isfixedarray(t) ? "array" : "slice";
yyerror("invalid %s index %N (index too large)", why, n->right);
}
} }
break; break;
@ -947,6 +951,8 @@ reswitch:
yyerror("invalid slice index %N (index must be non-negative)", n->right->left); yyerror("invalid slice index %N (index must be non-negative)", n->right->left);
else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->left->val.u.xval) > tp->bound) else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->left->val.u.xval) > tp->bound)
yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->left, tp->bound); yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->left, tp->bound);
else if(mpcmpfixfix(n->right->left->val.u.xval, maxintval[TINT]) > 0)
yyerror("invalid slice index %N (index too large)", n->right->left);
} }
} }
if(n->right->right != N) { if(n->right->right != N) {
@ -961,6 +967,8 @@ reswitch:
yyerror("invalid slice index %N (index must be non-negative)", n->right->right); yyerror("invalid slice index %N (index must be non-negative)", n->right->right);
else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->right->val.u.xval) > tp->bound) else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->right->val.u.xval) > tp->bound)
yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->right, tp->bound); yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->right, tp->bound);
else if(mpcmpfixfix(n->right->right->val.u.xval, maxintval[TINT]) > 0)
yyerror("invalid slice index %N (index too large)", n->right->right);
} }
} }
goto ret; goto ret;