[libunwind] b7a249d - [libunwind] Remove unnecessary strcpy dependency (#72043)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 15:41:57 PST 2023


Author: Michael Kenzel
Date: 2023-11-15T18:41:53-05:00
New Revision: b7a249d26fe61432050df470d23bdea417fda574

URL: https://github.com/llvm/llvm-project/commit/b7a249d26fe61432050df470d23bdea417fda574
DIFF: https://github.com/llvm/llvm-project/commit/b7a249d26fe61432050df470d23bdea417fda574.diff

LOG: [libunwind] Remove unnecessary strcpy dependency (#72043)

libunwind uses a minimal set of necessary standard library functions,
basically just `memset` and `memcpy`. There is a single use of `strcpy`
to copy the bytes `"CLNGUNW"` into a `uint64_t` object. This is both an
arguably odd use of the `strcpy` function as well as it unnecessarily
widens the set of library functions that must be available to build
libunwind, which can be an obstacle in baremetal scenarios. This change
simply replaces this one `strcpy` with the more fundamental `memcpy`.

Added: 
    

Modified: 
    libunwind/src/UnwindLevel1-gcc-ext.c
    libunwind/test/forceunwind.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libunwind/src/UnwindLevel1-gcc-ext.c b/libunwind/src/UnwindLevel1-gcc-ext.c
index d343f4e6e9cc837..32c872ffade1fd0 100644
--- a/libunwind/src/UnwindLevel1-gcc-ext.c
+++ b/libunwind/src/UnwindLevel1-gcc-ext.c
@@ -143,7 +143,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
   // Create a mock exception object for force unwinding.
   _Unwind_Exception ex;
   memset(&ex, '\0', sizeof(ex));
-  strcpy((char *)&ex.exception_class, "CLNGUNW");
+  memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class));
 #endif
 
   // walk each frame

diff  --git a/libunwind/test/forceunwind.pass.cpp b/libunwind/test/forceunwind.pass.cpp
index 8c26551b6d0b678..db499d8bc30894e 100644
--- a/libunwind/test/forceunwind.pass.cpp
+++ b/libunwind/test/forceunwind.pass.cpp
@@ -61,7 +61,7 @@ __attribute__((noinline)) void foo() {
 #if defined(_LIBUNWIND_ARM_EHABI)
   // Create a mock exception object.
   memset(e, '\0', sizeof(*e));
-  strcpy(reinterpret_cast<char *>(&e->exception_class), "CLNGUNW");
+  memcpy(&e->exception_class, "CLNGUNW", sizeof(e->exception_class));
 #endif
   _Unwind_ForcedUnwind(e, stop, (void *)&foo);
 }


        


More information about the cfe-commits mailing list