[Base/Kernel] Add and use truncating null-terminating string copying
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/string_util.h"
|
||||
#include "xenia/kernel/kernel_state.h"
|
||||
#include "xenia/kernel/user_module.h"
|
||||
#include "xenia/kernel/util/shim_utils.h"
|
||||
@@ -74,15 +75,15 @@ static SYSTEMTIME xeGetLocalSystemTime(uint64_t filetime) {
|
||||
|
||||
void XamFormatDateString(dword_t unk, qword_t filetime, lpvoid_t output_buffer,
|
||||
dword_t output_count) {
|
||||
std::memset(output_buffer, 0, output_count * 2);
|
||||
std::memset(output_buffer, 0, output_count * sizeof(char16_t));
|
||||
|
||||
// TODO: implement this for other platforms
|
||||
#if XE_PLATFORM_WIN32
|
||||
auto st = xeGetLocalSystemTime(filetime);
|
||||
// TODO: format this depending on users locale?
|
||||
auto str = fmt::format(u"{:02d}/{:02d}/{}", st.wMonth, st.wDay, st.wYear);
|
||||
auto copy_length = std::min(size_t(output_count), str.size()) * 2;
|
||||
xe::copy_and_swap(output_buffer.as<char16_t*>(), str.c_str(), copy_length);
|
||||
xe::string_util::copy_and_swap_truncating(output_buffer.as<char16_t*>(), str,
|
||||
output_count);
|
||||
#else
|
||||
assert_always();
|
||||
#endif
|
||||
@@ -91,15 +92,15 @@ DECLARE_XAM_EXPORT1(XamFormatDateString, kNone, kImplemented);
|
||||
|
||||
void XamFormatTimeString(dword_t unk, qword_t filetime, lpvoid_t output_buffer,
|
||||
dword_t output_count) {
|
||||
std::memset(output_buffer, 0, output_count * 2);
|
||||
std::memset(output_buffer, 0, output_count * sizeof(char16_t));
|
||||
|
||||
// TODO: implement this for other platforms
|
||||
#if XE_PLATFORM_WIN32
|
||||
auto st = xeGetLocalSystemTime(filetime);
|
||||
// TODO: format this depending on users locale?
|
||||
auto str = fmt::format(u"{:02d}:{:02d}", st.wHour, st.wMinute);
|
||||
auto copy_count = std::min(size_t(output_count), str.size());
|
||||
xe::copy_and_swap(output_buffer.as<char16_t*>(), str.c_str(), copy_count);
|
||||
xe::string_util::copy_and_swap_truncating(output_buffer.as<char16_t*>(), str,
|
||||
output_count);
|
||||
#else
|
||||
assert_always();
|
||||
#endif
|
||||
@@ -113,7 +114,7 @@ dword_result_t keXamBuildResourceLocator(uint64_t module,
|
||||
uint32_t buffer_count) {
|
||||
std::u16string path;
|
||||
if (!module) {
|
||||
path = fmt::format(u"file://media:/{0}.xzp#{0}", container, resource);
|
||||
path = fmt::format(u"file://media:/{}.xzp#{}", container, resource);
|
||||
XELOGD(
|
||||
"XamBuildResourceLocator({0}) returning locator to local file {0}.xzp",
|
||||
xe::to_utf8(container));
|
||||
@@ -121,8 +122,8 @@ dword_result_t keXamBuildResourceLocator(uint64_t module,
|
||||
path = fmt::format(u"section://{:X},{}#{}", (uint32_t)module, container,
|
||||
resource);
|
||||
}
|
||||
auto copy_count = std::min(size_t(buffer_count), path.size());
|
||||
xe::copy_and_swap(buffer_ptr.as<char16_t*>(), path.c_str(), copy_count);
|
||||
xe::string_util::copy_and_swap_truncating(buffer_ptr.as<char16_t*>(), path,
|
||||
buffer_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user