Fixed heap corruption in string retrievement, also avoid runtime error if string doesnt fit buffer
This commit is contained in:
parent
4dfb45c5f3
commit
db4ca91180
@ -156,7 +156,10 @@ DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsig
|
|||||||
{
|
{
|
||||||
if (storedStrings[i].id == stringId)
|
if (storedStrings[i].id == stringId)
|
||||||
{
|
{
|
||||||
strcpy_s(targetString, targetSize, storedStrings[i].string.c_str());
|
if (storedStrings[i].string.length() < targetSize) //Avoid runtime error.
|
||||||
|
strcpy_s(targetString, targetSize, storedStrings[i].string.c_str());
|
||||||
|
else
|
||||||
|
strcpy_s(targetString, targetSize, "\0"); //String doesnt fit, return empty string"
|
||||||
storedStrings.erase(storedStrings.begin() + i);
|
storedStrings.erase(storedStrings.begin() + i);
|
||||||
return targetString;
|
return targetString;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ msghandlerString(wParam, lParam, msg, hwnd) {
|
|||||||
stdout.Write("msghandlerString: ")
|
stdout.Write("msghandlerString: ")
|
||||||
|
|
||||||
VarSetCapacity(theStr, 20)
|
VarSetCapacity(theStr, 20)
|
||||||
theStr := DllCall("OSC2AHK.dll\getStringData", AStr, theStr, UInt, 20, UInt, lParam, "Cdecl AStr")
|
theStr := DllCall("OSC2AHK.dll\getStringData", str, theStr, UInt, 20, UInt, lParam, AStr)
|
||||||
|
|
||||||
stdout.WriteLine(theStr)
|
stdout.WriteLine(theStr)
|
||||||
stdout.Close()
|
stdout.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user