From 12b90600eb96c86ba1b5b80478be437d02b70891 Mon Sep 17 00:00:00 2001
From: obscuren <geffobscura@gmail.com>
Date: Thu, 28 May 2015 18:18:23 +0200
Subject: [PATCH] core: moved guards
---
core/chain_manager.go | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 86e90a815..3e8ef6fd8 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -680,21 +680,20 @@ func (self *ChainManager) diff(oldBlock, newBlock *types.Block) (types.Blocks, e
// first reduce whoever is higher bound
if oldBlock.NumberU64() > newBlock.NumberU64() {
// reduce old chain
- for oldBlock = oldBlock; oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) {
- if oldBlock == nil {
- return nil, fmt.Errorf("Invalid old chain")
- }
+ for oldBlock = oldBlock; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) {
}
} else {
// reduce new chain and append new chain blocks for inserting later on
- for newBlock = newBlock; newBlock.NumberU64() != oldBlock.NumberU64(); newBlock = self.GetBlock(newBlock.ParentHash()) {
- if newBlock == nil {
- return nil, fmt.Errorf("Invalid new chain")
- }
-
+ for newBlock = newBlock; newBlock != nil && newBlock.NumberU64() != oldBlock.NumberU64(); newBlock = self.GetBlock(newBlock.ParentHash()) {
newChain = append(newChain, newBlock)
}
}
+ if oldBlock == nil {
+ return nil, fmt.Errorf("Invalid old chain")
+ }
+ if newBlock == nil {
+ return nil, fmt.Errorf("Invalid new chain")
+ }
numSplit := newBlock.Number()
for {
--
GitLab