cx
cx copied to clipboard
Panic when trying to print a negative literal as a string with printf.
@asahi3g commented on Jul 3
To Reproduce
package main
func main()() {
printf("%s\n", -1)
panic(true, false, "must not compile")
}
Expected behavior
Compilation error eg golang:
Printf format %s has arg -1 of wrong type int
Ideally this should be done at compile time when the format string is a literal.
Screenshots
error: pending_10.cx:4, CX_RUNTIME_ERROR, runtime error: slice bounds out of range
===Callstack===
>>> main()
Expressions
pending_10.cx:5 : neg() : -1
goroutine 1 [running, locked to thread]:
runtime/debug.Stack(0x52, 0x0, 0x0)
/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/skycoin/cx/cx.runtimeErrorInfo(0xd78be0, 0x15cbcc0, 0x15cbc01, 0x5)
/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:836 +0x2c1
github.com/skycoin/cx/cx.RuntimeError()
/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:859 +0x16d
panic(0xd78be0, 0x15cbcc0)
/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.ReadStr(0x0, 0xc000169e60, 0xc000669807, 0x3)
/home/cxfx/go/src/github.com/skycoin/cx/cx/op.go:472 +0x2c2
github.com/skycoin/cx/cx.buildString(0xc000092140, 0x0, 0xc000032000, 0xeaa200, 0xc000198f48)
/home/cxfx/go/src/github.com/skycoin/cx/cx/op_und.go:494 +0x965
github.com/skycoin/cx/cx.opPrintf(0xc000092140, 0x0)
/home/cxfx/go/src/github.com/skycoin/cx/cx/op_und.go:561 +0x39
github.com/skycoin/cx/cx.init.2.func1(0xc00061e000)
/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_core.go:985 +0x324
github.com/skycoin/cx/cx.init.3.func1(0xc00061e000)
/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_extra.go:594 +0xfc3
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc0002ec000, 0xc00061e000, 0x0, 0x0)
/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:278 +0x331
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc00061e000, 0xe3ef01, 0xc000199250, 0xffffffffffffffff, 0x0, 0x0)
/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:118 +0x126
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc00061e000, 0x0, 0x0, 0x0, 0x0, 0xc000082680, 0x0)
/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:200 +0x231
main.main()
/home/cxfx/go/src/github.com/skycoin/cx/cxgo/main.go:1003 +0x24c3
Desktop:
- OS: Linux
- CX Version 0.0.7, commit: f999780
@ingwal commented on Sep 9
We should check the parameters to printf, but this isn't done yet. In the meantime, this should only give a runtime error and continue, but should not panic.