mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
undocumented behavior of LoadStringW: If nBufferMax is 0, LoadStringW will copy a pointer to the in-memory image of the string to the specified buffer and return the length of the string in WCHARs.
svn path=/trunk/; revision=26929
This commit is contained in:
parent
a009b642f6
commit
cf5b4c7e99
1 changed files with 99 additions and 77 deletions
|
@ -115,8 +115,10 @@ int STDCALL LoadStringA
|
|||
|
||||
/* get the UNICODE_STRING descriptor of the in-memory image of the string */
|
||||
if(!_InternalLoadString(hInstance, uID, &wstrResStr))
|
||||
{
|
||||
/* failure */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
convert the string. The Unicode string may be in UTF-16 (multi-byte), so we
|
||||
|
@ -127,13 +129,19 @@ int STDCALL LoadStringA
|
|||
strBuf.MaximumLength = nBufferMax * sizeof(CHAR);
|
||||
strBuf.Buffer = lpBuffer;
|
||||
|
||||
retSize = WideCharToMultiByte(CP_ACP, 0, wstrResStr.Buffer, wstrResStr.Length / sizeof(WCHAR), strBuf.Buffer, strBuf.MaximumLength, NULL, NULL);
|
||||
retSize = WideCharToMultiByte(CP_ACP, 0, wstrResStr.Buffer,
|
||||
wstrResStr.Length / sizeof(WCHAR),
|
||||
strBuf.Buffer, strBuf.MaximumLength, NULL, NULL);
|
||||
|
||||
if(!retSize)
|
||||
{
|
||||
/* failure */
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
strBuf.Length = retSize;
|
||||
}
|
||||
|
||||
/* the ANSI string may not be null-terminated */
|
||||
if(strBuf.Length >= strBuf.MaximumLength)
|
||||
|
@ -176,7 +184,11 @@ int STDCALL LoadStringW
|
|||
if
|
||||
(
|
||||
(nBufferMax < 1) ||
|
||||
(IsBadWritePtr(lpBuffer, nBufferMax * sizeof(lpBuffer[0])))
|
||||
((nBufferMax > 0) && IsBadWritePtr(lpBuffer, nBufferMax * sizeof(lpBuffer[0]))) ||
|
||||
/* undocumented: If nBufferMax is 0, LoadStringW will copy a pointer to the
|
||||
in-memory image of the string to the specified buffer and return the length
|
||||
of the string in WCHARs */
|
||||
((nBufferMax == 0) && IsBadWritePtr(lpBuffer, sizeof(lpBuffer)))
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
|
@ -185,23 +197,33 @@ int STDCALL LoadStringW
|
|||
|
||||
/* get the UNICODE_STRING descriptor of the in-memory image of the string */
|
||||
if(!_InternalLoadString(hInstance, uID, &wstrResStr))
|
||||
{
|
||||
/* failure */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get the length in characters */
|
||||
nStringLen = wstrResStr.Length / sizeof(WCHAR);
|
||||
|
||||
if (nBufferMax > 0)
|
||||
{
|
||||
/* the buffer must be enough to contain the string and the null terminator */
|
||||
if(nBufferMax < (nStringLen + 1))
|
||||
{
|
||||
/* otherwise, the string is truncated */
|
||||
nStringLen = nBufferMax - 1;
|
||||
}
|
||||
|
||||
/* copy the string */
|
||||
memcpy(lpBuffer, wstrResStr.Buffer, nStringLen * sizeof(WCHAR));
|
||||
|
||||
/* null-terminate it */
|
||||
lpBuffer[nStringLen] = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
*((LPWSTR*)lpBuffer) = wstrResStr.Buffer;
|
||||
}
|
||||
/* success */
|
||||
return nStringLen;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue