[lld] [lld][macho] Fix gcc category merging warning (PR #86091)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 21 08:49:17 PDT 2024
https://github.com/alx32 updated https://github.com/llvm/llvm-project/pull/86091
>From 36f1e1a6a71ac7d2d27427a1ef6f6e628548ef7e Mon Sep 17 00:00:00 2001
From: alx32 <103613512+alx32 at users.noreply.github.com>
Date: Wed, 20 Mar 2024 23:17:01 -0700
Subject: [PATCH 1/2] [lld][macho] Fix gcc category merging warning
---
lld/MachO/ObjC.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp
index 40df2243b26f06..831a5bcea3acfe 100644
--- a/lld/MachO/ObjC.cpp
+++ b/lld/MachO/ObjC.cpp
@@ -1221,9 +1221,10 @@ void ObjcCategoryMerger::doCleanup() { generatedSectionData.clear(); }
StringRef ObjcCategoryMerger::newStringData(const char *str) {
uint32_t len = strlen(str);
- auto &data = newSectionData(len + 1);
+ uint32_t bufSize = len + 1;
+ auto &data = newSectionData(bufSize);
char *strData = reinterpret_cast<char *>(data.data());
- strncpy(strData, str, len);
+ strncpy(strData, str, bufSize);
return StringRef(strData, len);
}
>From c13eeef4f70f372c2580800a232c0fb8016de7c4 Mon Sep 17 00:00:00 2001
From: alx32 <103613512+alx32 at users.noreply.github.com>
Date: Thu, 21 Mar 2024 08:49:09 -0700
Subject: [PATCH 2/2] Address Feedback #1
---
lld/MachO/ObjC.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp
index 831a5bcea3acfe..ded1e504d8ddf0 100644
--- a/lld/MachO/ObjC.cpp
+++ b/lld/MachO/ObjC.cpp
@@ -1224,7 +1224,8 @@ StringRef ObjcCategoryMerger::newStringData(const char *str) {
uint32_t bufSize = len + 1;
auto &data = newSectionData(bufSize);
char *strData = reinterpret_cast<char *>(data.data());
- strncpy(strData, str, bufSize);
+ // Copy the string chars and null-terminator
+ memcpy(strData, str, bufSize);
return StringRef(strData, len);
}
More information about the llvm-commits
mailing list