Skip to content

Commit 2279f70

Browse files
committed
Fix chain GetByHeight() to prevent potential crash on a returned nil pointer
This was missed when adapting to kernelApi_65
1 parent 1fa857a commit 2279f70

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

kernel/chain.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ func (c *Chain) GetGenesis() *BlockTreeEntry {
2929

3030
// GetByHeight returns the block tree entry for the given height in the chain, or nil if it does not exist
3131
func (c *Chain) GetByHeight(height int32) *BlockTreeEntry {
32-
tip := c.GetTip()
33-
if tip == nil || height > tip.Height() {
32+
ptr := C.btck_chain_get_by_height(c.ptr, C.int(height))
33+
if ptr == nil {
3434
return nil
3535
}
36-
ptr := C.btck_chain_get_by_height(c.ptr, C.int(height))
37-
return &BlockTreeEntry{check(ptr)}
36+
return &BlockTreeEntry{ptr}
3837
}
3938

4039
func (c *Chain) Contains(blockTreeEntry *BlockTreeEntry) bool {

0 commit comments

Comments
 (0)