[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:26 PDT 2024
https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/97933
…nment
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.
>From 2653b8a0ab3792a22570118ed3b90cb302879ab0 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Sat, 6 Jul 2024 19:22:01 -0700
Subject: [PATCH] [Clang] Protect ObjCMethodList assignment operator against
self-assignment
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.
---
clang/include/clang/Sema/ObjCMethodList.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Sema/ObjCMethodList.h b/clang/include/clang/Sema/ObjCMethodList.h
index 9e65e0d8e00af..c4465f6ab59fd 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;
}
More information about the cfe-commits
mailing list