enbImgLoader fixed

Fixing a stupid error in my plugin.

Panda kindly send me the enbImgLoader plugin crashlog which happened to people some times.

Skyrim SSE v1.6.640
CrashLoggerSSE v1-7-0-0 Jan 12 2023 23:41:20
 
Unhandled exception "EXCEPTION_ACCESS_VIOLATION" at 0x7FFD593AAB50 ntdll.dll+005AB50	mov r8d, [r9+0x04]

PROBABLE CALL STACK:
	[0] 0x7FFD593AAB50              ntdll.dll+005AB50
	[1] 0x7FFD56CED94C         KERNELBASE.dll+004D94C
	[2] 0x7FFCDC9F18D6 enbImgLoader.dllplugin+00218D6
	[3] 0x7FFCDC9F213F enbImgLoader.dllplugin+002213F
	[4] 0x7FFCDC9F216C enbImgLoader.dllplugin+002216C
	[5] 0x7FFD593B2260              ntdll.dll+0062260
	[6] 0x7FFD593A31AA              ntdll.dll+00531AA
	[7] 0x7FFD573A7614           KERNEL32.DLL+0017614
	[8] 0x7FFD593A26A1              ntdll.dll+00526A1

After looking at callstack and memory offset to the mod, the culprit is clearly this:

WideCharToMultiByte(CP_UTF8, 0, paths[idx].data(), MAX_PATH, buf, MAX_PATH * 2, NULL, NULL);

It is fine when input buffer is allocated with length MAX_PATH like I’m using in other places, but in this case, paths[idx] is not guaranteed such, hence access violation when conversion worker walks out of bound.

The fix is simply replacing MAX_PATH with -1

WideCharToMultiByte(CP_UTF8, 0, paths[idx].data(), -1, buf, MAX_PATH * 2, NULL, NULL);

As MSDN stated, -1 should tell the function to stop at null character ‘\n’, and solve the issue since paths[idx] is null terminated c-string.