diff --git a/Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs b/Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs index 9ea582118..a0440e30d 100644 --- a/Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs +++ b/Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs @@ -54,12 +54,12 @@ namespace Flow.Launcher.Plugin.SharedCommands { var capacity = PInvoke.GetWindowTextLength(hwnd) + 1; int length; - Span buffer = stackalloc char[capacity]; + Span buffer = capacity < 1024 ? stackalloc char[capacity] : new char[capacity]; fixed (char* pBuffer = buffer) { // If the window has no title bar or text, if the title bar is empty, // or if the window or control handle is invalid, the return value is zero. - length = PInvoke.GetWindowText(hwnd, (PWSTR)pBuffer, capacity); + length = PInvoke.GetWindowText(hwnd, pBuffer, capacity); } return buffer[..length].ToString();