From 84097fd526477bd876fe2756c12f45effcbb50ac Mon Sep 17 00:00:00 2001 From: "Brett T. Warden" Date: Wed, 24 Apr 2024 10:59:16 -0700 Subject: [PATCH] Don't alter a list we're iterating through Fix a couple of places where we're trying to remove files from the files list while we're iterating through it -- replicate the change elsewhere to keep a temporary list of the files to remove, then iterate through *that* list after iterating through the global files list. --- patchfilter.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/patchfilter.py b/patchfilter.py index 49e21e5..3343f19 100644 --- a/patchfilter.py +++ b/patchfilter.py @@ -98,9 +98,13 @@ def zap_entire_file_end(filename): global files global files_chunks global files_header + files_to_remove = list() for file in files: if file.endswith(filename): - files.remove(file) + # Don't modify the original list while iterating over it + files_to_remove.append(file) + for file in files_to_remove: + files.remove(file) def zap_line_in_file_substring(filename, match): global header @@ -186,7 +190,7 @@ def zap_empty_chunks(): files_to_remove = list() for file in files: if file not in files_chunks: - files.remove(file) + files_to_remove.append(file) continue to_remove = list() for chunk in files_chunks[file]: