Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Protect ObjCMethodList assignment operator against self-assignment #97933

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smanna12
Copy link
Contributor

@smanna12 smanna12 commented Jul 7, 2024

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.

…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.
@smanna12 smanna12 requested a review from tahonermann July 7, 2024 02:24
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 7, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 7, 2024

@llvm/pr-subscribers-clang

Author: None (smanna12)

Changes

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 --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;
   }
 

@smanna12 smanna12 changed the title [Clang] Protect ObjCMethodList assignment operator against self-assig… [Clang] Protect ObjCMethodList assignment operator against self-assignment Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants