From a797b350a0258794067be60cdd81d11e31f2dffa Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 19 Sep 2019 15:57:06 +0300 Subject: [PATCH] Improve strcpy_trunc Zero all remaining array --- Utilities/StrUtil.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index 526e767560..33e021f6ba 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -13,7 +13,7 @@ inline void strcpy_trunc(char (&dst)[N], const std::string& src) { const std::size_t count = src.size() >= N ? N - 1 : src.size(); std::memcpy(dst, src.c_str(), count); - dst[count] = '\0'; + std::memset(dst + count, 0, N - count); } // Copy null-terminated string from char array to another char array with truncation @@ -22,7 +22,7 @@ inline void strcpy_trunc(char (&dst)[N], const char (&src)[N2]) { const std::size_t count = N2 >= N ? N - 1 : N2; std::memcpy(dst, src, count); - dst[count] = '\0'; + std::memset(dst + count, 0, N - count); } template