sh icon indicating copy to clipboard operation
sh copied to clipboard

interp: panic on division by zero

Open dankegel opened this issue 3 years ago • 1 comments

Given the invalid command

let x/x

bash rightfully complains:

$ let x/x
bash: let: x/x: division by 0 (error token is "x")

but gosh panics:

$ go run cmd/gosh/main.go
$ let x/x
panic: runtime error: integer divide by zero

goroutine 1 [running]:
mvdan.cc/sh/v3/expand.binArit(0x111540?, 0x589de0?, 0xc000122f28?)
	/home/dank/src/sh/expand/arith.go:173 +0x245
mvdan.cc/sh/v3/expand.Arithm(0x0?, {0x589840?, 0xc000078480?})
	/home/dank/src/sh/expand/arith.go:95 +0x353
...

This happens in v3.0.0 and master. I didn't try any tags older than v3.0.0. Tested with go 1.18.1.

dankegel avatar Jun 29 '22 01:06 dankegel

Thanks, this does look like a bug. Happy to accept a patch with a test.

mvdan avatar Jun 30 '22 14:06 mvdan