check for unsigned int overflow
Merge pull request #549 from amro/fix_layout_index_oob

check for unsigned int overflow