Add comments for string truncation

This commit is contained in:
Jack251970 2024-12-14 11:17:29 +08:00
parent 8a05c606e4
commit a088f91541
4 changed files with 6 additions and 0 deletions

View file

@ -62,6 +62,7 @@ namespace Flow.Launcher.Plugin.SharedCommands
return string.Empty;
}
// Truncate the buffer to the actual length of the string
int validLength = Array.IndexOf(buffer, '\0');
if (validLength < 0) validLength = capacity;
return new string(buffer, 0, validLength);

View file

@ -61,6 +61,8 @@ public class WindowsInteropHelper
fixed (char* pBuffer = buffer)
{
PInvoke.GetClassName(hWnd, pBuffer, capacity);
// Truncate the buffer to the actual length of the string
int validLength = Array.IndexOf(buffer, '\0');
if (validLength < 0) validLength = capacity;
windowClass = new string(buffer, 0, validLength);

View file

@ -106,6 +106,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
return string.Empty;
}
// Truncate the buffer to the actual length of the string
int validLength = Array.IndexOf(buffer, '\0');
if (validLength < 0) validLength = (int)capacity;
return new string(buffer, 0, validLength);

View file

@ -38,6 +38,8 @@ namespace Flow.Launcher.Plugin.Program.Programs
fixed (char* bufferChar = buffer)
{
((IShellLinkW)link).GetPath((PWSTR)bufferChar, MAX_PATH, &data, (uint)SLGP_FLAGS.SLGP_SHORTPATH);
// Truncate the buffer to the actual length of the string
int validLength = Array.IndexOf(buffer, '\0');
if (validLength < 0) validLength = MAX_PATH;
target = new string(buffer, 0, validLength);