Make divide-by-zero error, handle error gracefully in grow
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package vm
|
||||
|
||||
import "fmt"
|
||||
import "math"
|
||||
|
||||
type opHandler func(*State, *Instruction)
|
||||
@@ -79,8 +80,7 @@ func (state *State) handleDivideUnsigned(instr *Instruction) {
|
||||
in2 := state.readUnsigned(instr.Operands[1])
|
||||
|
||||
if in2 == 0 {
|
||||
// Divide by zero just returns zero
|
||||
state.writeUnsigned(instr.Operands[0], 0)
|
||||
state.setError(fmt.Errorf("Divide by zero"))
|
||||
} else {
|
||||
state.writeUnsigned(instr.Operands[0], in1/in2)
|
||||
}
|
||||
@@ -91,8 +91,7 @@ func (state *State) handleDivideSigned(instr *Instruction) {
|
||||
in2 := state.readSigned(instr.Operands[1])
|
||||
|
||||
if in2 == 0 {
|
||||
// Divide by zero just returns zero
|
||||
state.writeSigned(instr.Operands[0], 0)
|
||||
state.setError(fmt.Errorf("Divide by zero"))
|
||||
} else {
|
||||
state.writeSigned(instr.Operands[0], in1/in2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user