diff --git a/include/libtorrent/stack_allocator.hpp b/include/libtorrent/stack_allocator.hpp index 84ea3bfd8..d31bc951a 100644 --- a/include/libtorrent/stack_allocator.hpp +++ b/include/libtorrent/stack_allocator.hpp @@ -80,7 +80,8 @@ namespace libtorrent { namespace aux int const ret = int(m_storage.size()); int const len = int(std::strlen(str)); m_storage.resize(ret + len + 1); - std::strcpy(&m_storage[ret], str); + std::memcpy(&m_storage[ret], str, len); + m_storage[ret + len] = '\0'; return allocation_slot(ret); } diff --git a/src/string_util.cpp b/src/string_util.cpp index 42530bec6..f1ad3946e 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -160,9 +160,11 @@ namespace libtorrent char* allocate_string_copy(char const* str) { if (str == nullptr) return nullptr; - char* tmp = static_cast(std::malloc(std::strlen(str) + 1)); + int const len = int(std::strlen(str)); + char* tmp = static_cast(std::malloc(len + 1)); if (tmp == nullptr) return nullptr; - std::strcpy(tmp, str); + std::memcpy(tmp, str, len); + tmp[len] = '\0'; return tmp; }