Added check to avoid buffer overflow.
am: 821e838a51

Change-Id: I51ba3a2eed6394696157a578d19e168fcaa77e8b