From baa2768a6980a015117d3df001f33faa34e1eb57 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi Date: Sat, 17 Dec 2022 20:21:54 +0200 Subject: [PATCH] StrUtil.h: Prevent an overflow in strcpy_trunc --- Utilities/StrUtil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index aefedc9556..432f18d924 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -16,7 +16,7 @@ std::string utf16_to_utf8(std::u16string_view src); template inline void strcpy_trunc(D& dst, const T& src) { - const usz count = std::size(src) >= std::size(dst) ? std::size(dst) - 1 : std::size(src); + const usz count = std::size(src) >= std::size(dst) ? std::max(std::size(dst), 1) - 1 : std::size(src); std::memcpy(std::data(dst), std::data(src), count); std::memset(std::data(dst) + count, 0, std::size(dst) - count); }