From 9350e82b7793414871dcc59ae95a5b84268aa365 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Fri, 27 Dec 2024 12:57:17 -0600 Subject: [PATCH] only stackalloc the getwindowtitle buffer when length is small. --- Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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();