From 9a82005cb8e3d516b43064651b056df6e57128e2 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Thu, 5 Aug 2021 12:42:33 -0700 Subject: [PATCH] PR comments/fixes Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../AzCore/AzCore/std/string/conversions.h | 26 ++++++++++++------- .../WinAPI/AzCore/Utils/Utils_WinAPI.cpp | 2 +- .../Linux/AzCore/Debug/Trace_Linux.cpp | 2 +- Code/Framework/AzCore/Tests/AZStd/String.cpp | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/std/string/conversions.h b/Code/Framework/AzCore/AzCore/std/string/conversions.h index 91af1029b4..235eb188d1 100644 --- a/Code/Framework/AzCore/AzCore/std/string/conversions.h +++ b/Code/Framework/AzCore/AzCore/std/string/conversions.h @@ -58,15 +58,15 @@ namespace AZStd } } - static inline void to_string(char* dest, size_t destSize, const wchar_t* first, const wchar_t* last) + static inline char* to_string(char* dest, size_t destSize, const wchar_t* first, const wchar_t* last) { if constexpr (Size == 2) { - Utf8::Unchecked::utf16to8(first, last, dest, destSize); + return Utf8::Unchecked::utf16to8(first, last, dest, destSize); } else if constexpr (Size == 4) { - Utf8::Unchecked::utf32to8(first, last, dest, destSize); + return Utf8::Unchecked::utf32to8(first, last, dest, destSize); } } @@ -96,15 +96,15 @@ namespace AZStd } } - static inline void to_wstring(wchar_t* dest, size_t destSize, const char* first, const char* last) + static inline wchar_t* to_wstring(wchar_t* dest, size_t destSize, const char* first, const char* last) { if constexpr (Size == 2) { - Utf8::Unchecked::utf8to16(first, last, dest, destSize); + return Utf8::Unchecked::utf8to16(first, last, dest, destSize); } else if constexpr (Size == 4) { - Utf8::Unchecked::utf8to32(first, last, dest, destSize); + return Utf8::Unchecked::utf8to32(first, last, dest, destSize); } } }; @@ -337,7 +337,11 @@ namespace AZStd if (srcLen > 0) { - Internal::WCharTPlatformConverter<>::to_string(dest, destSize, str, str + srcLen + 1); // copy null terminator + char* endStr = Internal::WCharTPlatformConverter<>::to_string(dest, destSize, str, str + srcLen); + if (*(endStr - 1) != '\0') + { + *endStr = '\0'; // copy null terminator + } } } @@ -485,12 +489,16 @@ namespace AZStd { if (srcLen == 0) { - srcLen = strlen(str) + 1; + srcLen = strlen(str); } if (srcLen > 0) { - Internal::WCharTPlatformConverter<>::to_wstring(dest, destSize, str, str + srcLen + 1); // copy null terminator + wchar_t* endWStr = Internal::WCharTPlatformConverter<>::to_wstring(dest, destSize, str, str + srcLen); + if (*(endWStr - 1) != '\0') + { + *endWStr = '\0'; // copy null terminator + } } } diff --git a/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp b/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp index a4af19a2a4..dc104668be 100644 --- a/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp +++ b/Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp @@ -30,7 +30,7 @@ namespace AZ result.m_pathIncludesFilename = true; // Platform specific get exe path: http://stackoverflow.com/a/1024937 // https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea - wchar_t pathBufferW[AZ_MAX_PATH_LEN] = { 0 }; + wchar_t pathBufferW[AZ::IO::MaxPathLength] = { 0 }; const DWORD pathLen = GetModuleFileNameW(nullptr, pathBufferW, static_cast(exeStorageSize)); const DWORD errorCode = GetLastError(); if (pathLen == exeStorageSize && errorCode == ERROR_INSUFFICIENT_BUFFER) diff --git a/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Trace_Linux.cpp b/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Trace_Linux.cpp index 86c7e14ae6..1ca06fcf7f 100644 --- a/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Trace_Linux.cpp +++ b/Code/Framework/AzCore/Platform/Linux/AzCore/Debug/Trace_Linux.cpp @@ -15,7 +15,7 @@ namespace AZ { namespace Platform { - void OutputToDebugger(const char* title, const char* message) + void OutputToDebugger([[maybe_unused]] const char* title, [[maybe_unused]] const char* message) { // std::cout << title << ": " << message; } diff --git a/Code/Framework/AzCore/Tests/AZStd/String.cpp b/Code/Framework/AzCore/Tests/AZStd/String.cpp index c0d378bd39..309f561a75 100644 --- a/Code/Framework/AzCore/Tests/AZStd/String.cpp +++ b/Code/Framework/AzCore/Tests/AZStd/String.cpp @@ -703,7 +703,7 @@ namespace UnitTest AZ_TEST_ASSERT(0 == azwcsicmp(wstrBuffer, L"BlaBla 5")); // char buffer to wchar_t buffer - memset(wstrBuffer, 0, AZ_ARRAY_SIZE(wstrBuffer)); + memset(wstrBuffer, L' ', AZ_ARRAY_SIZE(wstrBuffer)); // to check that the null terminator is properly placed to_wstring(wstrBuffer, 9, strBuffer); AZ_TEST_ASSERT(0 == azwcsicmp(wstrBuffer, L"BLABLA 5"));