Fixed a couple of #6276 integer over/underflow issues