Skip to content

Commit 5a7acb2

Browse files
authored
[llvm-foreach] Adjust output var usage for --out-increment (#3772)
When using --out-increment, the output string was being populated and put into the Args vector using the same variable as the --out-replace causing a potential overwrite problem. Use a new var for out-increment.
1 parent 7e4a386 commit 5a7acb2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/tools/llvm-foreach/llvm-foreach.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ int main(int argc, char **argv) {
166166
error(EC, "error opening the file '" + OutputFileList + "'");
167167

168168
std::string ResOutArg;
169+
std::string IncOutArg;
169170
std::vector<std::string> ResInArgs(InReplaceArgs.size());
170171
std::string ResFileList = "";
171172
for (size_t j = 0; j != FileLists[0].size(); ++j) {
@@ -213,10 +214,10 @@ int main(int argc, char **argv) {
213214

214215
if (!OutIncrement.empty()) {
215216
// Name the file by adding the current file list index to the name.
216-
ResOutArg = InputCommandArgs[OutIncrementArg.ArgNum];
217+
IncOutArg = InputCommandArgs[OutIncrementArg.ArgNum];
217218
if (j > 0)
218-
ResOutArg += ("_" + Twine(j)).str();
219-
Args[OutIncrementArg.ArgNum] = ResOutArg;
219+
IncOutArg += ("_" + Twine(j)).str();
220+
Args[OutIncrementArg.ArgNum] = IncOutArg;
220221
}
221222

222223
std::string ErrMsg;

0 commit comments

Comments
 (0)