remove compile warning in clang

1] remove compile warning in clang
2] add check condition when value is not in valid range.