[PATCH] [libc++abi] Use memcpy() instead of strcpy() in stdexcept.cpp

Matthew Dempsky matthew at dempsky.org
Fri Jun 7 19:06:44 PDT 2013


We already computed "len = strlen(msg)" earlier, so no point in using
strcpy() when we can use memcpy() which should be faster.

Index: src/stdexcept.cpp
===================================================================
--- src/stdexcept.cpp	(revision 183600)
+++ src/stdexcept.cpp	(working copy)
@@ -80,7 +80,7 @@ __libcpp_nmstr::__libcpp_nmstr(const char* msg)
     c->len = c->cap = len;
     str_ += offset;
     count() = 0;
-    std::strcpy(const_cast<char*>(c_str()), msg);
+    std::memcpy(const_cast<char*>(c_str()), msg, len + 1);
 }
 
 inline



More information about the cfe-commits mailing list