From 0e6cd82908f5c649e15e6a63ad77a94f627449d2 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 2 Nov 2018 02:35:49 +0100 Subject: Fix removal of multiple consecutive 'if' nodes Despite 'if' nodes being flattened before 'if' removal, consecutive 'if' nodes can still show up for code like the following: ... if X endif if X endif ... _remove_ifs() failed to remove the second 'if' node, leading to a crash e.g. when turning on show-all mode in the menuconfig in a menu with such code (due to the unexpected 'if' node). Stuff like the above could potentially result from 'osource's with no matches, though I just spotted the error while looking over the code. Fix the 'if' removal logic to properly handle consecutive 'if' nodes. --- kconfiglib.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index eae271e..96e6b52 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5822,17 +5822,17 @@ def _remove_ifs(node): node.list = cur while cur: - if cur.next and not cur.next.item: - # Equivalent to - # - # tmp = cur.next.next - # cur.next = tmp - # cur = tmp - # - # due to tricky Python semantics. The order matters. - cur.next = cur = cur.next.next - else: - cur = cur.next + next = cur.next + while next and not next.item: + next = next.next + + # Equivalent to + # + # cur.next = next + # cur = next + # + # due to tricky Python semantics. The order matters. + cur.next = cur = next def _finalize_choice(node): # Finalizes a choice, marking each symbol whose menu node has the choice as -- cgit v1.2.3