mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
StrUtil.h: Prevent an overflow in strcpy_trunc
This commit is contained in:
parent
04fb86556a
commit
baa2768a69
1 changed files with 1 additions and 1 deletions
|
@ -16,7 +16,7 @@ std::string utf16_to_utf8(std::u16string_view src);
|
||||||
template <typename D, typename T>
|
template <typename D, typename T>
|
||||||
inline void strcpy_trunc(D& dst, const T& src)
|
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<usz>(std::size(dst), 1) - 1 : std::size(src);
|
||||||
std::memcpy(std::data(dst), std::data(src), count);
|
std::memcpy(std::data(dst), std::data(src), count);
|
||||||
std::memset(std::data(dst) + count, 0, std::size(dst) - count);
|
std::memset(std::data(dst) + count, 0, std::size(dst) - count);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue