Add out of bound check for the index before do the update

Signed-off-by: Yongqin Liu  <liuyq0307@thundersoft.com>