Skip to content

Commit 9350e82

Browse files
committed
only stackalloc the getwindowtitle buffer when length is small.
1 parent 02a4566 commit 9350e82

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ private static unsafe string GetWindowTitle(HWND hwnd)
5454
{
5555
var capacity = PInvoke.GetWindowTextLength(hwnd) + 1;
5656
int length;
57-
Span<char> buffer = stackalloc char[capacity];
57+
Span<char> buffer = capacity < 1024 ? stackalloc char[capacity] : new char[capacity];
5858
fixed (char* pBuffer = buffer)
5959
{
6060
// If the window has no title bar or text, if the title bar is empty,
6161
// or if the window or control handle is invalid, the return value is zero.
62-
length = PInvoke.GetWindowText(hwnd, (PWSTR)pBuffer, capacity);
62+
length = PInvoke.GetWindowText(hwnd, pBuffer, capacity);
6363
}
6464

6565
return buffer[..length].ToString();

0 commit comments

Comments
 (0)