From 97f8b8b6eec733a5d0f0cb144c78956ff7f3a988 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 27 Nov 2023 16:57:56 -0800 Subject: [PATCH] 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 --- scripts/footprint/fpdiff.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/footprint/fpdiff.py b/scripts/footprint/fpdiff.py index fe9c40bc40d..c76bf4a5806 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 @@ def main(): 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):