From b1db91b575432d8f175c9abfa409aa0c5fb50dd9 Mon Sep 17 00:00:00 2001 From: Erik Parker Date: Wed, 16 Jun 2021 14:52:58 -0500 Subject: [PATCH] Change winres.py exec_command to not empty the cmd list. --- waflib/Tools/winres.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/waflib/Tools/winres.py b/waflib/Tools/winres.py index 73c0e953..b5bc915f 100644 --- a/waflib/Tools/winres.py +++ b/waflib/Tools/winres.py @@ -69,12 +69,29 @@ class winrc(Task.Task): # response files and are best passed as environment variables replace_cmd = [] incpaths = [] - while cmd: + # Work off of a copy of cmd. cmd is essentially passed by reference, + # so if we pop items off of it, that modifies the version of cmd + # that is passed into this function. Normally this might only + # manifest as some weirdness if someone walks up the stack with + # the debugger. That person would get to whoever called this + # function and see that the original cmd was empty. gcc_color.py's + # format function walks up the stack and access the cmd variable, + # which is the cmd variable at the time this function is called. + # Since this function was popping elements off of cmd and eventually + # replacing cmd with replace_cmd, by the time the fiormat function + # got to caller function cmd was empty. Since format only tests to + # see if cmd is a list and not if cmd is empty, format was throwing + # an IndexException. We fi the issue here by operating off of a copy + # of cmd instead of operating off of the original. That does mean + # that after this function cmd will be different, but that shouldn't + # caudse any other headaches. + working_cmd = cmd[:] + while working_cmd: # filter include path flags - flag = cmd.pop(0) + flag = working_cmd.pop(0) if flag.upper().startswith('/I'): if len(flag) == 2: - incpaths.append(cmd.pop(0)) + incpaths.append(working_cmd.pop(0)) else: incpaths.append(flag[2:]) else: