Skip to content

Commit

Permalink
fix: Fix potential nil errors
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Nov 27, 2023
1 parent 9e5f066 commit 983746d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/isc/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ func AddressFromReader(rr *rwutil.Reader) (address iotago.Address) {
if kind == addressIsNil {
return nil
}
addrSize := 0
if rr.Err == nil {
address, rr.Err = iotago.AddressSelector(uint32(kind))
if rr.Err != nil {
addrSize = 0
} else {
addrSize = address.Size()
}
}
rr.PushBack().WriteKind(kind)
rr.ReadSerialized(address, math.MaxUint16, address.Size())
rr.ReadSerialized(address, math.MaxUint16, addrSize)
return address
}

Expand Down
3 changes: 3 additions & 0 deletions packages/isc/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func RequestsInTransaction(tx *iotago.Transaction) (map[ChainID][]Request, error
if err != nil {
return nil, err
}
if tx.Essence == nil {
return nil, fmt.Errorf("malformed transaction")
}

ret := make(map[ChainID][]Request)
for i, output := range tx.Essence.Outputs {
Expand Down
4 changes: 4 additions & 0 deletions packages/state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (s *store) extractBlock(d StateDraft) (Block, *buffered.Mutations, trie.Com

var baseTrieRoot trie.Hash
{
if d == nil {
panic("state.StateDraft is nil")
}

baseL1Commitment := d.BaseL1Commitment()
if baseL1Commitment != nil {
if !s.db.hasBlock(baseL1Commitment.TrieRoot()) {
Expand Down
3 changes: 3 additions & 0 deletions packages/vm/gas/feepolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (p *FeePolicy) IsEnoughForMinimumFee(availableTokens uint64) bool {
// if GasPerToken is '0:0' then set the GasBudget to MaxGasPerRequest
func (p *FeePolicy) GasBudgetFromTokens(availableTokens uint64, limits ...*Limits) uint64 {
if p.GasPerToken.IsZero() {
if len(limits) == 0 {
panic("GasBudgetFromTokens without giving limits when GasPerToken")
}
return limits[0].MaxGasPerRequest
}
return p.GasPerToken.XFloor64(availableTokens)
Expand Down

0 comments on commit 983746d

Please sign in to comment.