From c1c8b1eda26b647bb3b079ca8cb9f7489d11eb37 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 22 Aug 2017 16:02:53 +0200 Subject: [PATCH] tools: ratbagctl: fixes for parsing arguments We shouldn't try to access input_string[0] if len(input_string) is null. Meaning a condition in the break in the while loop could be checked earlier (or later). Signed-off-by: Benjamin Tissoires --- tools/ratbagctl.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index 1b83baff..750f54fd 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -1144,7 +1144,7 @@ class RatbagParserSwitch(RatbagParser): parser.set_defaults(subparse=self.sub_parse) def _sub_parse(self, input_string, ns): - if len(input_string) >= 0 and self.N_access is not None: + if len(input_string) > 0 and self.N_access is not None: # retrieve first numbered element if any try: int(input_string[0]) @@ -1301,10 +1301,10 @@ class RatbagParserRoot(object): ns.subparse = None - while subparser: + while rest and subparser: old_rest = rest ns, rest = subparser.parse_known_args(rest, namespace=ns) - if not rest or old_rest == rest: + if old_rest == rest: break pr_debug(ns, ns, rest) if ns.subparse: