Skip to content

Commit

Permalink
Merge pull request #37 from icon-project/eunki-fix-nullptr
Browse files Browse the repository at this point in the history
Fix nullptr exception
  • Loading branch information
kornery authored Nov 30, 2023
2 parents 8ee5beb + 5c7f3ee commit f52acad
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static BlockTree readObject(ObjectReader r) {
List<Item> items = new ArrayList<>();
items.add(new Item(nleaves, root));

while(items.size() > 0) {
while(!items.isEmpty()) {
Item item = items.remove(0);
Hash id = item.id;
List<Hash> children = new ArrayList<>();
Expand All @@ -79,12 +79,12 @@ public static void writeObject(ObjectWriter w, BlockTree o) {
List<Hash> children = new ArrayList<>();
children.add(o.root);
w.beginList(o.nodes.size());
while (children.size() > 0) {
while (!children.isEmpty()) {
Hash node = children.remove(0);
List<Hash> tmp = o.nodes.get(node);
w.write(tmp.size());
w.write(node);
if (tmp.size() > 0) {
if (!tmp.isEmpty()) {
children.addAll(tmp);
}
}
Expand Down Expand Up @@ -155,9 +155,13 @@ public interface OnRemoveListener {
}

public void prune(Hash until, OnRemoveListener lst) {
if (until.equals(root)) {
return;
}

List<Hash> removals = new ArrayList<>();
removals.add(root);
while (removals.size() > 0) {
while (!removals.isEmpty()) {
List<Hash> buf = new ArrayList<>();
for (Hash removal : removals) {
List<Hash> leaves = nodes.get(removal);
Expand All @@ -178,7 +182,7 @@ public void prune(Hash until, OnRemoveListener lst) {

@Override
public String toString() {
return "BlockTrie{" +
return "BlockTree{" +
"root=" + root +
", nodes=" + nodes +
'}';
Expand Down
50 changes: 40 additions & 10 deletions bmv/bsc2/src/test/resources/testnet.json

Large diffs are not rendered by default.

0 comments on commit f52acad

Please sign in to comment.