Skip to content

Commit b7a249d

Browse files
[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`.
1 parent 917a550 commit b7a249d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

libunwind/src/UnwindLevel1-gcc-ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
143143
// Create a mock exception object for force unwinding.
144144
_Unwind_Exception ex;
145145
memset(&ex, '\0', sizeof(ex));
146-
strcpy((char *)&ex.exception_class, "CLNGUNW");
146+
memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class));
147147
#endif
148148

149149
// walk each frame

libunwind/test/forceunwind.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ __attribute__((noinline)) void foo() {
6161
#if defined(_LIBUNWIND_ARM_EHABI)
6262
// Create a mock exception object.
6363
memset(e, '\0', sizeof(*e));
64-
strcpy(reinterpret_cast<char *>(&e->exception_class), "CLNGUNW");
64+
memcpy(&e->exception_class, "CLNGUNW", sizeof(e->exception_class));
6565
#endif
6666
_Unwind_ForcedUnwind(e, stop, (void *)&foo);
6767
}

0 commit comments

Comments
 (0)