panic: runtime error: invalid memory address or nil pointer dereference

4 篇文章 0 订阅

报错:

panic: runtime error: invalid memory address or nil pointer dereference

[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x488c7d]

goroutine 29 [running]:

panic(0xa0cb60, 0xc420016040)

/opt/go/src/runtime/panic.go:500 +0x1a1

github.com/hyperledger/fabric-samples/chaincode/cpabe/vendor/github.com/fentec-project/gofe/abe.(*FAME).Encrypt(0xc4201321c8, 0xc4204fc170, 0xf, 0xc420135540, 0x0, 0x0, 0x0, 0x0)

/chaincode/input/src/github.com/hyperledger/fabric-samples/chaincode/cpabe/vendor/github.com/fentec-project/gofe/abe/fame.go:134 +0x44d

main.(*SmartContract).Encryption(0xfcc8a0, 0xf93c40, 0xc420078080, 0xc4201b8520, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, ...)

/chaincode/input/src/github.com/hyperledger/fabric-samples/chaincode/cpabe/cpabe.go:172 +0x92a

main.(*SmartContract).Invoke(0xfcc8a0, 0xf93c40, 0xc420078080, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)

/chaincode/input/src/github.com/hyperledger/fabric-samples/chaincode/cpabe/cpabe.go:67 +0x208

github.com/hyperledger/fabric/core/chaincode/shim.(*Handler).handleTransaction.func1(0xc4201482a0, 0xc420246410)

/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/handler.go:317 +0x483

created by github.com/hyperledger/fabric/core/chaincode/shim.(*Handler).handleTransaction

/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/handler.go:328 +0x49

 

解决方案

找到line134前面是一个空值判断

 打印函数传递的参数发现确实有空值,给参数正确赋值就能解决。可见,这个bug的原因应该就是函数调用时传了一个空值。

一个需要注意的坑是go语言中,json无法访问我们的结构体里小写字母开头的成员,所以用json.Marshal()和json.Unmarshal()时很可能得到一个空值。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值