[libunwind] [libunwind] Remove unnecessary strcpy dependency (PR #72043)

Alexander Richardson via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 12 16:49:27 PST 2023


================
@@ -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));
----------------
arichardson wrote:

I agree this is fine as is. Assigning the integer directly will cause endian issues, so using memcpy is better.

If we want to be extra safe, we could #define the string value and  add a static_assert().

https://github.com/llvm/llvm-project/pull/72043


More information about the cfe-commits mailing list