Skip to content

Commit 943eec4

Browse files
committed
INIHelper Increase MAX_LENGTH #48
1 parent bf2d12f commit 943eec4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

dev/DevWinUI/Helpers/InIHelper.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,19 @@ public string ReadValue(string key)
3131
/// <returns></returns>
3232
public string ReadValue(string key, string section)
3333
{
34-
const int MAX_LENGTH = 255;
35-
Span<char> buffer = stackalloc char[MAX_LENGTH];
34+
return ReadValue(key, section, 1024);
35+
}
36+
37+
/// <summary>
38+
/// Read Data Value From the Ini File
39+
/// </summary>
40+
/// <param name="key">must be unique</param>
41+
/// <param name="section"></param>
42+
/// <param name="maxLength">512 - 1024 chars (~1 KB - 2 KB) → Very safe, 2048 - 4096 chars (~4 KB - 8 KB) → Generally safe, but risky in deep call stacks</param>
43+
/// <returns></returns>
44+
public string ReadValue(string key, string section, int maxLength)
45+
{
46+
Span<char> buffer = stackalloc char[maxLength];
3647

3748
uint result = PInvoke.GetPrivateProfileString(section ?? GetProductName(), key, string.Empty, buffer, FilePath);
3849

dev/DevWinUI/Helpers/PathHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static string GetAppDataFolderPath(bool forceUnpackagedMode = false)
5858
/// <returns></returns>
5959
public static string GetExecutablePathNative()
6060
{
61-
const int MAX_Length = 255;
61+
const int MAX_Length = 1024;
6262
Span<char> buffer = stackalloc char[MAX_Length];
6363
var hModule = PInvoke.GetModuleHandle(string.Empty);
6464
SafeHandle safeHandle = new Microsoft.Win32.SafeHandles.SafeFileHandle(hModule.DangerousGetHandle(), ownsHandle: false);

0 commit comments

Comments
 (0)