addressing PR comments/suggestions

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
monroegm-disable-blank-issue-2
Esteban Papp 4 years ago
parent 84623dfb66
commit 895dc09176

@ -338,7 +338,7 @@ namespace AZStd
if (srcLen > 0)
{
char* endStr = Internal::WCharTPlatformConverter<>::to_string(dest, destSize, str, str + srcLen);
if (*(endStr - 1) != '\0')
if (endStr < (dest + destSize) && *(endStr - 1) != '\0')
{
*endStr = '\0'; // copy null terminator
}
@ -495,7 +495,7 @@ namespace AZStd
if (srcLen > 0)
{
wchar_t* endWStr = Internal::WCharTPlatformConverter<>::to_wstring(dest, destSize, str, str + srcLen);
if (*(endWStr - 1) != '\0')
if (endWStr < (dest + destSize) && *(endWStr - 1) != '\0')
{
*endWStr = '\0'; // copy null terminator
}

@ -251,6 +251,54 @@ namespace Utf8::Unchecked
return result;
}
static constexpr size_t utf8_codepoint_length(AZ::u32 cp)
{
if (cp < 0x80)
{
return 1;
}
else if (cp < 0x800)
{
return 2;
}
else if (cp < 0x10000)
{
return 3;
}
return 4;
}
template <typename u16bit_iterator>
size_t utf16ToUtf8BytesRequired(u16bit_iterator start, u16bit_iterator end)
{
size_t bytesRequired = 0;
while (start != end)
{
AZ::u32 cp = Utf8::Internal::mask16(*start++);
// Take care of surrogate pairs first
if (Utf8::Internal::is_lead_surrogate(cp))
{
AZ::u32 trail_surrogate = Utf8::Internal::mask16(*start++);
cp = (cp << 10) + trail_surrogate + Internal::SURROGATE_OFFSET;
}
bytesRequired += utf8_codepoint_length(cp);
}
return bytesRequired;
}
template <typename u32bit_iterator>
size_t utf32ToUtf8BytesRequired(u32bit_iterator start, u32bit_iterator end)
{
size_t bytesRequired = 0;
while (start != end)
{
bytesRequired += utf8_codepoint_length(*start++);
}
return bytesRequired;
}
} // namespace Utf8::Unchecked

@ -31,7 +31,7 @@ namespace AZ
// 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::IO::MaxPathLength] = { 0 };
const DWORD pathLen = GetModuleFileNameW(nullptr, pathBufferW, static_cast<DWORD>(exeStorageSize));
const DWORD pathLen = GetModuleFileNameW(nullptr, pathBufferW, static_cast<DWORD>(AZStd::size(pathBufferW)));
const DWORD errorCode = GetLastError();
if (pathLen == exeStorageSize && errorCode == ERROR_INSUFFICIENT_BUFFER)
{
@ -43,7 +43,15 @@ namespace AZ
}
else
{
AZStd::to_string(exeStorageBuffer, exeStorageSize, pathBufferW);
size_t utf8PathSize = Utf8::Unchecked::utf16ToUtf8BytesRequired(pathBufferW, pathBufferW + pathLen);
if (utf8PathSize >= exeStorageSize)
{
result.m_pathStored = ExecutablePathResult::BufferSizeNotLargeEnough;
}
else
{
AZStd::to_string(exeStorageBuffer, exeStorageSize, pathBufferW);
}
}
return result;

@ -90,7 +90,7 @@ namespace AZ {
{
case CBA_EVENT:
evt = (PIMAGEHLP_CBA_EVENT)CallbackData;
_tprintf(_T("%s"), evt->desc);
printf("%s", evt->desc);
break;
default:

@ -132,9 +132,7 @@ const CTypeInfo&PtrTypeInfo()
// bool
AZStd::string ToString(bool const& val)
{
static AZStd::fixed_string<5> sTrue = "true";
static AZStd::fixed_string<6> sFalse = "false";
return val ? sTrue.c_str() : sFalse.c_str();
return val ? "true" : "false";
}
bool FromString(bool& val, cstr s)

@ -19,7 +19,7 @@ namespace AZ
{
namespace DataTypes
{
static AZStd::string s_advancedDisabledString = "Disabled";
static const char* s_advancedDisabledString = "Disabled";
class IMeshAdvancedRule
: public IRule

Loading…
Cancel
Save