gmp icon indicating copy to clipboard operation
gmp copied to clipboard

runtime error: makeslice: len out of range

Open JianJunVictory opened this issue 6 years ago • 7 comments

What's the reason?

type Amount struct{
      gmp.Int
}

when I use Int.Bytes(),it happens at the first time,and then run code again,it's ok.

JianJunVictory avatar Apr 02 '19 06:04 JianJunVictory

Can you post a short example of the problem please? Some thing I can run preferably. Thanks

ncw avatar Apr 02 '19 20:04 ncw

` // here fmt.Printf("%#v",amount.Int) gmp.Int{i:gmp._Ctype_mpz_t{gmp._Ctype_struct___0{_mp_alloc:1, _mp_size:1, _mp_d:(*gmp._Ctype_ulong)(0x34b5010)}}, init:true}panic: runtime error: makeslice: len out of range

goroutine 1 [running]: github.com/dappley/go-dappley/vendor/github.com/ncw/gmp.(*Int).Bytes(0xc42017eee0, 0x4, 0xc4201d1878, 0x1) /home/jun/goPath/src/github.com/dappley/go-dappley/vendor/github.com/ncw/gmp/int.go:685 +0x77 github.com/dappley/go-dappley/core.(*Transaction).GetToHashBytes(0xc4200b0320, 0xc4200d2620, 0xc4201d19e8, 0x4176b8) /home/jun/goPath/src/github.com/dappley/go-dappley/core/transaction.go:208 +0x57a github.com/dappley/go-dappley/core.(*Transaction).Hash(0xc4200b0320, 0xc4201c4420, 0x22, 0xc4200a5da0) /home/jun/goPath/src/github.com/dappley/go-dappley/core/transaction.go:222 +0x49 github.com/dappley/go-dappley/core.NewGenesisBlock(0xc91458, 0x22, 0xc4201d1b90) /home/jun/goPath/src/github.com/dappley/go-dappley/core/genesis.go:31 +0x2b6 github.com/dappley/go-dappley/core.CreateBlockchain(0xc91458, 0x22, 0xe36c40, 0xc4200a07f0, 0xe37180, 0xc4200b0280, 0x6400000, 0xe2e0e0, 0xc4200a0810, 0x6400000, ...) /home/jun/goPath/src/github.com/dappley/go-dappley/core/blockchain.go:74 +0x50 github.com/dappley/go-dappley/logic.CreateBlockchain(0xc91458, 0x22, 0xe36c40, 0xc4200a07f0, 0xe37180, 0xc4200b0280, 0xc406400000, 0xc4200a0810, 0x6400000, 0xe2b360, ...) /home/jun/goPath/src/github.com/dappley/go-dappley/logic/logic.go:54 +0xc0 main.main() /home/jun/goPath/src/github.com/dappley/go-dappley/dapp/main.go:86 +0x81d exit status 2

`

https://github.com/dappley/go-dappley/tree/sc I change "math/big" to "gmp" in common / amount.go . When I run "go run main.go" at first time ,it happens.

JianJunVictory avatar Apr 03 '19 03:04 JianJunVictory

I couldn't make go-dappley compile :-(

The problem with gmp must be here

https://github.com/ncw/gmp/blob/22a058044a92d3096aec89da13b381dbb7606e42/int.go#L684-L699

z.BitLen() must be returning a negative number for the make([]byte...) to panic

Which means C.mpz_sizeinbase must be returning a negative number.

I don't know why it should do that unless the z pointer is invalid somehow.

Any thoughts on how I can replicate this?

ncw avatar Apr 10 '19 20:04 ncw

@ncw

The problem with gmp must be here

yes.

If z is a null pointer, will it happen?

JianJunVictory avatar Apr 12 '19 09:04 JianJunVictory

@ncw If z is a null pointer, will it happen?

I tried with z null and calling C.mpz_sizeinbase(nil, 2) and they both give SEGV rather than anything else.

So something weird is going on! Is there concurrency in the test program? What version of libgmp do you have?

ncw avatar Apr 12 '19 12:04 ncw

What version of libgmp do you have?

v1.0.4

Is there concurrency in the test program?

Is the program here referring to my own program? if so,yes,there is data race. What you mean is that the passed parameter is a null pointer, caused by data race in my program?

JianJunVictory avatar Apr 15 '19 02:04 JianJunVictory

What version of libgmp do you have?

v1.0.4

That seems very old, I'm using 6.1.2 from dpkg -l | grep libgmp

Is there concurrency in the test program?

Is the program here referring to my own program?

The program which gave the error.

if so,yes,there is data race. What you mean is that the passed parameter is a null pointer, caused by data race in my program?

If there are concurrency problems then that can cause memory corruptions.

Have you tried building your program with the go build -race flag?

ncw avatar Apr 16 '19 09:04 ncw