Fix bugs in grain where values could go out of bounds.

Change-Id: Ib2cc3177424cf24bc81b75786dfd9be30fea5378
1 file changed