Merge "Fix potential overflows" am: a0c1eb865f am: ef3542347c
am: 2774f292b7

Change-Id: I1c46b0367639fa29830c74ce92f14c295d178b2c