Added check to avoid buffer overflow. am: 0c88db8f89 am: 34c7896853
am: b1ad9f571f

Change-Id: I8a54d12f8666602dd43c8ae0109d3cea77537410