Fixed many invalid uses of StringView::GetText(), where a null-terminated string was required.

Renamed GetText() to GetNonTerminatedText() to reduce chance of same bugs appearing in the future.
This commit is contained in:
Zbigniew Skowron
2021-08-08 22:04:54 +02:00
parent 6ac0d5d3f4
commit aecc81f5e5
14 changed files with 158 additions and 108 deletions

View File

@@ -169,8 +169,8 @@ public:
/// <summary>
/// Copy memory region
/// </summary>
/// <param name="dst">Destination memory address</param>
/// <param name="src">Source memory address</param>
/// <param name="dst">Destination memory address. Must not be null, even if size is zero.</param>
/// <param name="src">Source memory address. Must not be null, even if size is zero.</param>
/// <param name="size">Size of the memory to copy in bytes</param>
FORCE_INLINE static void MemoryCopy(void* dst, const void* src, uint64 size)
{
@@ -180,7 +180,7 @@ public:
/// <summary>
/// Set memory region with given value
/// </summary>
/// <param name="dst">Destination memory address</param>
/// <param name="dst">Destination memory address. Must not be null, even if size is zero.</param>
/// <param name="size">Size of the memory to set in bytes</param>
/// <param name="value">Value to set</param>
FORCE_INLINE static void MemorySet(void* dst, uint64 size, int32 value)
@@ -191,7 +191,7 @@ public:
/// <summary>
/// Clear memory region with zeros
/// </summary>
/// <param name="dst">Destination memory address</param>
/// <param name="dst">Destination memory address. Must not be null, even if size is zero.</param>
/// <param name="size">Size of the memory to clear in bytes</param>
FORCE_INLINE static void MemoryClear(void* dst, uint64 size)
{
@@ -201,8 +201,8 @@ public:
/// <summary>
/// Compare two blocks of the memory.
/// </summary>
/// <param name="buf1">The first buffer address.</param>
/// <param name="buf2">The second buffer address.</param>
/// <param name="buf1">The first buffer address. Must not be null, even if size is zero.</param>
/// <param name="buf2">The second buffer address. Must not be null, even if size is zero.</param>
/// <param name="size">Size of the memory to compare in bytes.</param>
FORCE_INLINE static int32 MemoryCompare(const void* buf1, const void* buf2, uint64 size)
{

View File

@@ -1659,7 +1659,7 @@ void LinuxClipboard::SetText(const StringView& text)
return;
X11::Window window = (X11::Window)mainWindow->GetNativePtr();
Impl::ClipboardText.Set(text.GetText(), text.Length());
Impl::ClipboardText.Set(text.Get(), text.Length());
X11::XSetSelectionOwner(xDisplay, xAtomClipboard, window, CurrentTime); // CLIPBOARD
X11::XSetSelectionOwner(xDisplay, (X11::Atom)1, window, CurrentTime); // XA_PRIMARY
}

View File

@@ -120,36 +120,36 @@ public:
public:
// Compare two strings with case sensitive
// Compare two strings with case sensitive. Strings must not be null.
static int32 Compare(const Char* str1, const Char* str2);
// Compare two strings without case sensitive
// Compare two strings without case sensitive. Strings must not be null.
static int32 Compare(const Char* str1, const Char* str2, int32 maxCount);
// Compare two strings without case sensitive
// Compare two strings without case sensitive. Strings must not be null.
static int32 CompareIgnoreCase(const Char* str1, const Char* str2);
// Compare two strings without case sensitive
// Compare two strings without case sensitive. Strings must not be null.
static int32 CompareIgnoreCase(const Char* str1, const Char* str2, int32 maxCount);
// Compare two strings with case sensitive
// Compare two strings with case sensitive. Strings must not be null.
static int32 Compare(const char* str1, const char* str2);
// Compare two strings without case sensitive
// Compare two strings without case sensitive. Strings must not be null.
static int32 Compare(const char* str1, const char* str2, int32 maxCount);
// Compare two strings without case sensitive
// Compare two strings without case sensitive. Strings must not be null.
static int32 CompareIgnoreCase(const char* str1, const char* str2);
// Compare two strings without case sensitive
// Compare two strings without case sensitive. Strings must not be null.
static int32 CompareIgnoreCase(const char* str1, const char* str2, int32 maxCount);
public:
// Get string length
// Get string length. Returns 0 if str is null.
static int32 Length(const Char* str);
// Get string length
// Get string length. Returns 0 if str is null.
static int32 Length(const char* str);
// Copy string

View File

@@ -35,7 +35,7 @@ void RunUWP()
DialogResult MessageBox::Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
return (DialogResult)CUWPPlatform->ShowMessageDialog(parent ? parent->GetImpl() : nullptr, text.GetText(), caption.GetText(), (UWPPlatformImpl::MessageBoxButtons)buttons, (UWPPlatformImpl::MessageBoxIcon)icon);
return (DialogResult)CUWPPlatform->ShowMessageDialog(parent ? parent->GetImpl() : nullptr, String(text).GetText(), String(caption).GetText(), (UWPPlatformImpl::MessageBoxButtons)buttons, (UWPPlatformImpl::MessageBoxIcon)icon);
}
bool UWPPlatform::Init()

View File

@@ -25,7 +25,7 @@ void WindowsClipboard::SetText(const StringView& text)
{
const int32 size = (text.Length() + 1) * sizeof(Char);
const HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, size);
Platform::MemoryCopy(GlobalLock(hMem), text.GetText(), size);
Platform::MemoryCopy(GlobalLock(hMem), String(text).GetText(), size);
GlobalUnlock(hMem);
OpenClipboard(nullptr);

View File

@@ -435,7 +435,7 @@ DialogResult MessageBox::Show(Window* parent, const StringView& text, const Stri
}
// Show dialog
int result = MessageBoxW(parent ? static_cast<HWND>(parent->GetNativePtr()) : nullptr, text.GetText(), caption.GetText(), flags);
int result = MessageBoxW(parent ? static_cast<HWND>(parent->GetNativePtr()) : nullptr, String(text).GetText(), String(caption).GetText(), flags);
// Translate result to dialog result
DialogResult dialogResult;
@@ -948,10 +948,12 @@ int32 WindowsPlatform::StartProcess(const StringView& filename, const StringView
LOG(Info, "Working directory: {0}", workingDir);
}
String filenameString(filename);
SHELLEXECUTEINFOW shExecInfo = { 0 };
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExecInfo.lpFile = filename.GetText();
shExecInfo.lpFile = filenameString.GetText();
shExecInfo.lpParameters = args.HasChars() ? args.Get() : nullptr;
shExecInfo.lpDirectory = workingDir.HasChars() ? workingDir.Get() : nullptr;
shExecInfo.nShow = hiddenWindow ? SW_HIDE : SW_SHOW;
@@ -1109,7 +1111,7 @@ int32 WindowsPlatform::RunProcess(const StringView& cmdLine, const StringView& w
// Create the process
PROCESS_INFORMATION procInfo;
if (!CreateProcessW(nullptr, const_cast<LPWSTR>(cmdLine.GetText()), nullptr, nullptr, TRUE, dwCreationFlags, (LPVOID)environmentStr, workingDir.HasChars() ? workingDir.Get() : nullptr, &startupInfoEx.StartupInfo, &procInfo))
if (!CreateProcessW(nullptr, const_cast<LPWSTR>(String(cmdLine).GetText()), nullptr, nullptr, TRUE, dwCreationFlags, (LPVOID)environmentStr, String(workingDir).GetText(), &startupInfoEx.StartupInfo, &procInfo))
{
LOG(Warning, "Cannot start process '{0}'. Error code: 0x{1:x}", cmdLine, static_cast<int64>(GetLastError()));
goto ERROR_EXIT;