) demo
# This is a demo of ivy. Type a newline to advance to each new step. Type one now.
? 2 ** 32
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x49ace4]
goroutine 6 [running]:
robpike.io/ivy/parse.(*Parser).runFromReader.func1()
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/parse/special.go:358 +0x1ea
panic({0x4fa4e0, 0x5fbc80})
/home/aurelien/sdk/go1.17.4/src/runtime/panic.go:1038 +0x215
robpike.io/ivy/parse.(*Parser).runUntilError.func1()
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/parse/special.go:384 +0x1ea
panic({0x4fa4e0, 0x5fbc80})
/home/aurelien/sdk/go1.17.4/src/runtime/panic.go:1038 +0x215
math/big.(*Int).Add(0xc0000a8080, 0x49a93f, 0x0)
/home/aurelien/sdk/go1.17.4/src/math/big/int.go:118 +0x24
robpike.io/ivy/value.bigIntRand({0x544d70, 0xc0000753e0}, 0xffffffffffffffff, 0x4108b7)
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/value/unary.go:56 +0x77
robpike.io/ivy/value.unaryBigIntOp({0x544d70, 0xc0000753e0}, 0x5201e0, {0x544eb0, 0xc0000a8060})
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/value/unary.go:21 +0x8d
robpike.io/ivy/value.init.1.func2({0x544d70, 0xc0000753e0}, {0x544eb0, 0xc0000a8060})
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/value/unary.go:137 +0x71
robpike.io/ivy/value.(*unaryOp).EvalUnary(0xc00007e050, {0x544d70, 0xc0000753e0}, {0x544eb0, 0xc0000a8060})
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/value/eval.go:52 +0x119
robpike.io/ivy/exec.(*Context).EvalUnary(0xc0000753e0, {0xc0000a2020, 0x1}, {0x544eb0, 0xc0000a8060})
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/exec/context.go:138 +0x128
robpike.io/ivy/parse.(*unary).Eval(0xc0000a8000, {0x544d70, 0xc0000753e0})
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/parse/parse.go:193 +0x62
robpike.io/ivy/parse.(*Parser).runUntilError(0xc00009c000, {0x50f24a, 0x0})
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/parse/special.go:389 +0x113
robpike.io/ivy/parse.(*Parser).runFromReader(0xc000154d80, {0x544d70, 0xc0000753e0}, {0x50f24a, 0x0}, {0x541ca0, 0xc000176d80}, 0x0)
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/parse/special.go:362 +0x3ca
created by robpike.io/ivy/parse.DemoRunner
/home/aurelien/godev/pkg/mod/robpike.io/[email protected]/parse/special.go:434 +0x1ef
The fix is easy but since this is relatively minor (only happens during demo) and since there are different ways to fix it I'm not opening a PR, preferring to check if you're interested to fix this, and how.
diff --git a/config/config.go b/config/config.go
index 74b2a8e..4c210d3 100644
--- a/config/config.go
+++ b/config/config.go
@@ -57,6 +57,7 @@ func (c *Config) init() {
c.output = os.Stdout
c.errOutput = os.Stderr
c.origin = 1
+ c.bigOrigin = big.NewInt(1)
c.seed = time.Now().UnixNano()
c.source = rand.NewSource(c.seed)
c.random = rand.New(c.source)
@@ -171,6 +172,7 @@ func (c *Config) Origin() int {
// BigOrigin returns the index origin as a *big.Int.
func (c *Config) BigOrigin() *big.Int {
+ c.init()
return c.bigOrigin
}