Skip to content

Commit a088f91

Browse files
committed
Add comments for string truncation
1 parent 8a05c60 commit a088f91

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private static unsafe string GetWindowTitle(HWND hwnd)
6262
return string.Empty;
6363
}
6464

65+
// Truncate the buffer to the actual length of the string
6566
int validLength = Array.IndexOf(buffer, '\0');
6667
if (validLength < 0) validLength = capacity;
6768
return new string(buffer, 0, validLength);

Flow.Launcher/Helper/WindowsInteropHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public unsafe static bool IsWindowFullscreen()
6161
fixed (char* pBuffer = buffer)
6262
{
6363
PInvoke.GetClassName(hWnd, pBuffer, capacity);
64+
65+
// Truncate the buffer to the actual length of the string
6466
int validLength = Array.IndexOf(buffer, '\0');
6567
if (validLength < 0) validLength = capacity;
6668
windowClass = new string(buffer, 0, validLength);

Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public unsafe string TryGetProcessFilename(Process p)
106106
return string.Empty;
107107
}
108108

109+
// Truncate the buffer to the actual length of the string
109110
int validLength = Array.IndexOf(buffer, '\0');
110111
if (validLength < 0) validLength = (int)capacity;
111112
return new string(buffer, 0, validLength);

Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public unsafe string retrieveTargetPath(string path)
3838
fixed (char* bufferChar = buffer)
3939
{
4040
((IShellLinkW)link).GetPath((PWSTR)bufferChar, MAX_PATH, &data, (uint)SLGP_FLAGS.SLGP_SHORTPATH);
41+
42+
// Truncate the buffer to the actual length of the string
4143
int validLength = Array.IndexOf(buffer, '\0');
4244
if (validLength < 0) validLength = MAX_PATH;
4345
target = new string(buffer, 0, validLength);

0 commit comments

Comments
 (0)