Fix warnings in emucore

This commit is contained in:
Nekotekina Aux1 2020-03-04 17:08:40 +03:00 committed by Nekotekina
parent f2f3321952
commit 250736ece5
48 changed files with 189 additions and 193 deletions

View file

@ -7,22 +7,13 @@
#include <functional>
#include <string_view>
// Copy null-terminated string from std::string to char array with truncation
template <std::size_t N>
inline void strcpy_trunc(char (&dst)[N], const std::string& src)
// Copy null-terminated string from a std::string or a char array to a char array with truncation
template <typename D, typename T>
inline void strcpy_trunc(D& dst, const T& src)
{
const std::size_t count = src.size() >= N ? N - 1 : src.size();
std::memcpy(dst, src.c_str(), count);
std::memset(dst + count, 0, N - count);
}
// Copy null-terminated string from char array to another char array with truncation
template <std::size_t N, std::size_t N2>
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);
std::memset(dst + count, 0, N - count);
const std::size_t count = std::size(src) >= std::size(dst) ? std::size(dst) - 1 : std::size(src);
std::memcpy(std::data(dst), std::data(src), count);
std::memset(std::data(dst) + count, 0, std::size(dst) - count);
}
namespace fmt