scripts/footprint: Avoid fpdiff failure when data changes lots
Bounds check the array access in case the input data changes so that the
number of entries in the 'children' array is not the same. The tool output
with this change isn't terribly useful, but at least it doesn't crash.
Signed-off-by: Keith Packard <keithp@keithp.com>
diff --git a/scripts/footprint/fpdiff.py b/scripts/footprint/fpdiff.py
index fe9c40b..c76bf4a5 100755
--- a/scripts/footprint/fpdiff.py
+++ b/scripts/footprint/fpdiff.py
@@ -15,7 +15,7 @@
# ./scripts/footprint/fpdiff.py ram1.json ram2.json
from anytree.importer import DictImporter
-from anytree import PreOrderIter
+from anytree import PreOrderIter, AnyNode
from anytree.search import find
import colorama
@@ -46,7 +46,10 @@
for idx, ch in enumerate(data1['symbols']['children']):
root1 = importer.import_(ch)
- root2 = importer.import_(data2['symbols']['children'][idx])
+ if idx >= len(data2['symbols']['children']):
+ root2 = AnyNode(identifier=None)
+ else:
+ root2 = importer.import_(data2['symbols']['children'][idx])
print(f"{root1.name}\n+++++++++++++++++++++")
for node in PreOrderIter(root1):