Remove overflow and detect it if it happen again.

Reported by Ma ChienLi
The second commit is another crash reported by Peng Qi