Add overflow/underflow checks to find errors

Redmine: ref #2580