Added check to avoid buffer overflow.
am: 0c88db8f89

Change-Id: Ib28b5575e53ef9c2ab1f55619ec1febab642be52