[clang] [Clang] Protect ObjCMethodList assignment operator against self-assig… (PR #97933)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 6 19:24:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (smanna12)
<details>
<summary>Changes</summary>
This patch adds a self-assignment check to the ObjCMethodList assignment operator to prevent issues when an object is assigned to itself.
The fix ensures the integrity of the object's data during such assignments.
---
Full diff: https://github.com/llvm/llvm-project/pull/97933.diff
1 Files Affected:
- (modified) clang/include/clang/Sema/ObjCMethodList.h (+4-2)
``````````diff
diff --git a/clang/include/clang/Sema/ObjCMethodList.h b/clang/include/clang/Sema/ObjCMethodList.h
index 9e65e0d8e00af1..c4465f6ab59fd7 100644
--- a/clang/include/clang/Sema/ObjCMethodList.h
+++ b/clang/include/clang/Sema/ObjCMethodList.h
@@ -37,8 +37,10 @@ struct ObjCMethodList {
NextAndExtraBits(L.NextAndExtraBits) {}
ObjCMethodList &operator=(const ObjCMethodList &L) {
- MethodAndHasMoreThanOneDecl = L.MethodAndHasMoreThanOneDecl;
- NextAndExtraBits = L.NextAndExtraBits;
+ if (this != &L) { // Check for self-assignment
+ MethodAndHasMoreThanOneDecl = L.MethodAndHasMoreThanOneDecl;
+ NextAndExtraBits = L.NextAndExtraBits;
+ }
return *this;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/97933
More information about the cfe-commits
mailing list