Resolve #827: Avoid undefined behavior by adding proper bounds checking
to signed addition