[PATCH] D158134: Guard against self-assignment in InputArgList
Andy Kaylor via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 17:06:59 PDT 2023
andrew.w.kaylor created this revision.
andrew.w.kaylor added reviewers: dblaikie, bkramer.
Herald added a project: All.
andrew.w.kaylor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The InputArgList move assignment operator releases memory before copying fields, but it doesn't check against self-assignment. I haven't seen the self-assignment happen, but it doesn't look safe.
https://reviews.llvm.org/D158134
Files:
llvm/include/llvm/Option/ArgList.h
Index: llvm/include/llvm/Option/ArgList.h
===================================================================
--- llvm/include/llvm/Option/ArgList.h
+++ llvm/include/llvm/Option/ArgList.h
@@ -419,11 +419,13 @@
NumInputArgStrings(RHS.NumInputArgStrings) {}
InputArgList &operator=(InputArgList &&RHS) {
- releaseMemory();
- ArgList::operator=(std::move(RHS));
- ArgStrings = std::move(RHS.ArgStrings);
- SynthesizedStrings = std::move(RHS.SynthesizedStrings);
- NumInputArgStrings = RHS.NumInputArgStrings;
+ if (this != &RHS) {
+ releaseMemory();
+ ArgList::operator=(std::move(RHS));
+ ArgStrings = std::move(RHS.ArgStrings);
+ SynthesizedStrings = std::move(RHS.SynthesizedStrings);
+ NumInputArgStrings = RHS.NumInputArgStrings;
+ }
return *this;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158134.550938.patch
Type: text/x-patch
Size: 822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230817/2b4a424c/attachment.bin>
More information about the llvm-commits
mailing list