mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
Improve strcpy_trunc
Zero all remaining array
This commit is contained in:
parent
caef52e3b3
commit
a797b350a0
1 changed files with 2 additions and 2 deletions
|
@ -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();
|
const std::size_t count = src.size() >= N ? N - 1 : src.size();
|
||||||
std::memcpy(dst, src.c_str(), count);
|
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
|
// 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;
|
const std::size_t count = N2 >= N ? N - 1 : N2;
|
||||||
std::memcpy(dst, src, count);
|
std::memcpy(dst, src, count);
|
||||||
dst[count] = '\0';
|
std::memset(dst + count, 0, N - count);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue