Skip to content

Avoid recursion - #696

Merged
kristelmerilain merged 1 commit into
masterfrom
recursion
Oct 2, 2025
Merged

Avoid recursion#696
kristelmerilain merged 1 commit into
masterfrom
recursion

Conversation

@metsma

@metsma metsma commented Sep 23, 2025

Copy link
Copy Markdown
Contributor

IB-8611

Signed-off-by: Raul Metsma raul@metsma.ee

Comment thread src/SignatureTST.cpp
metadata.push_back({uri, string(ref["MimeType"]), std::move(tst)});
};
add("META-INF/ASiCArchiveManifest.xml", "text/xml");
for(auto ref = doc/"DataObjectReference"; ref; ref++)

Check notice

Code scanning / CodeQL

Declaration hides variable Note

Variable ref hides another variable of the same name (on
line 83
).

Copilot Autofix

AI 12 months ago

To fix this problem, the name of the variable declared in the inner for-loop on line 87 should be changed so that it does not shadow the outer variable from line 80. The best approach is to rename the inner loop variable to something more descriptive, such as dataRef. This change only requires updating the loop variable to dataRef and updating all uses within the loop, which are currently ref. Since this for-loop is small, only a handful of places require the change:

  • Line 87: for(auto ref = ...; ref; ref++)for(auto dataRef = ...; dataRef; dataRef++)
  • Lines 89, 91, 92: All instances of ref["Rootfile"], ref["URI"], ref["MimeType"] should be replaced with dataRef[... ]

No imports or other method/variable definitions are needed: only the use of the loop variable. All changes are to src/SignatureTST.cpp in the region of lines 87–94.


Suggested changeset 1
src/SignatureTST.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/SignatureTST.cpp b/src/SignatureTST.cpp
--- a/src/SignatureTST.cpp
+++ b/src/SignatureTST.cpp
@@ -84,12 +84,12 @@
             metadata.emplace_back(std::move(uri), string(ref["MimeType"]), std::move(tst));
             file.clear();
 
-            for(auto ref = doc/"DataObjectReference"; ref; ref++)
+            for(auto dataRef = doc/"DataObjectReference"; dataRef; dataRef++)
             {
-                if(ref["Rootfile"] == "true")
+                if(dataRef["Rootfile"] == "true")
                 {
-                    file = util::File::fromUriPath(ref["URI"]);
-                    mime = ref["MimeType"];
+                    file = util::File::fromUriPath(dataRef["URI"]);
+                    mime = dataRef["MimeType"];
                 }
             }
         }
EOF
@@ -84,12 +84,12 @@
metadata.emplace_back(std::move(uri), string(ref["MimeType"]), std::move(tst));
file.clear();

for(auto ref = doc/"DataObjectReference"; ref; ref++)
for(auto dataRef = doc/"DataObjectReference"; dataRef; dataRef++)
{
if(ref["Rootfile"] == "true")
if(dataRef["Rootfile"] == "true")
{
file = util::File::fromUriPath(ref["URI"]);
mime = ref["MimeType"];
file = util::File::fromUriPath(dataRef["URI"]);
mime = dataRef["MimeType"];
}
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
IB-8611

Signed-off-by: Raul Metsma <raul@metsma.ee>
@kristelmerilain
kristelmerilain merged commit fad3e40 into master Oct 2, 2025
44 checks passed
@kristelmerilain
kristelmerilain deleted the recursion branch October 2, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants