mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 08:53:02 +00:00
Fix the ntstrsafe.h tests to make sense, actually succeed using ntstrsafe.h from Win10 (10.0.15063), and fix ReactOS' ntstrsafe.h to also pass these tests. (#1859)
This commit is contained in:
parent
46ed46c73f
commit
c8681feee9
2 changed files with 159 additions and 191 deletions
|
@ -15,20 +15,6 @@
|
|||
#pragma warning(disable:28719) /* disable banned api usage warning */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#ifndef C_ASSERT
|
||||
#ifdef _MSC_VER
|
||||
# define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
|
||||
#else
|
||||
# define C_ASSERT(e) extern void __C_ASSERT__(int [(e)?1:-1])
|
||||
#endif
|
||||
#endif /* C_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define _STRSAFE_EXTERN_C extern "C"
|
||||
#else
|
||||
#define _STRSAFE_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
#define NTSTRSAFEAPI static __inline NTSTATUS NTAPI
|
||||
#define NTSTRSAFEVAPI static __inline NTSTATUS __cdecl
|
||||
#define NTSTRSAFE_INLINE_API static __inline NTSTATUS NTAPI
|
||||
|
@ -92,10 +78,8 @@ NTSTRSAFEAPI RtlStringCatNExWorkerA(STRSAFE_LPSTR pszDest, size_t cchDest, size_
|
|||
NTSTRSAFEAPI RtlStringCatNExWorkerW(STRSAFE_LPWSTR pszDest, size_t cchDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cchToAppend, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags);
|
||||
NTSTRSAFEAPI RtlStringVPrintfWorkerA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszFormat, va_list argList);
|
||||
NTSTRSAFEAPI RtlStringVPrintfWorkerW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat, va_list argList);
|
||||
NTSTRSAFEAPI RtlStringVPrintfWorkerLenW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat, size_t* pcchDestNewLen, va_list argList);
|
||||
NTSTRSAFEAPI RtlStringVPrintfExWorkerA(STRSAFE_LPSTR pszDest, size_t cchDest, size_t cbDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat, va_list argList);
|
||||
NTSTRSAFEAPI RtlStringVPrintfExWorkerW(STRSAFE_LPWSTR pszDest, size_t cchDest, size_t cbDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat, va_list argList);
|
||||
NTSTRSAFEAPI RtlStringVPrintfExWorkerLenW(STRSAFE_LPWSTR pszDest, size_t cchDest, size_t cbDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat, size_t* pcchDestNewLen, va_list argList);
|
||||
NTSTRSAFEAPI RtlUnicodeStringValidate(PCUNICODE_STRING SourceString);
|
||||
|
||||
NTSTRSAFEAPI
|
||||
|
@ -1366,6 +1350,7 @@ RtlStringCbPrintfExW(
|
|||
{
|
||||
if (cchDest > 0)
|
||||
*pszDest = L'\0';
|
||||
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
@ -2842,6 +2827,29 @@ NTSTRSAFEAPI RtlStringVPrintfWorkerA(
|
|||
return Status;
|
||||
}
|
||||
|
||||
NTSTRSAFEAPI RtlpArrayVPrintfWorkerW(
|
||||
STRSAFE_LPWSTR pszDest,
|
||||
size_t cchDest,
|
||||
STRSAFE_LPCWSTR pszFormat,
|
||||
size_t* pcchDestNewLen,
|
||||
va_list argList)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
int iRet = _vsnwprintf(pszDest, cchDest, pszFormat, argList);
|
||||
|
||||
if ((iRet < 0) || (((size_t)iRet) > cchDest))
|
||||
{
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
*pcchDestNewLen = cchDest;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pcchDestNewLen = iRet;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTRSAFEAPI RtlpStringVPrintfWorkerW(
|
||||
STRSAFE_LPWSTR pszDest,
|
||||
size_t cchDest,
|
||||
|
@ -2883,19 +2891,6 @@ NTSTRSAFEAPI RtlStringVPrintfWorkerW(
|
|||
return RtlpStringVPrintfWorkerW(pszDest, cchDest, pszFormat, NULL, argList);
|
||||
}
|
||||
|
||||
NTSTRSAFEAPI RtlStringVPrintfWorkerLenW(
|
||||
STRSAFE_LPWSTR pszDest,
|
||||
size_t cchDest,
|
||||
STRSAFE_LPCWSTR pszFormat,
|
||||
size_t* pcchDestNewLen,
|
||||
va_list argList)
|
||||
{
|
||||
if (cchDest == 0 || pcchDestNewLen == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
return RtlpStringVPrintfWorkerW(pszDest, cchDest, pszFormat, pcchDestNewLen, argList);
|
||||
}
|
||||
|
||||
NTSTRSAFEAPI RtlStringVPrintfExWorkerA(
|
||||
STRSAFE_LPSTR pszDest,
|
||||
size_t cchDest,
|
||||
|
@ -3068,35 +3063,19 @@ NTSTRSAFEAPI RtlpStringVPrintfExWorkerW(
|
|||
}
|
||||
else
|
||||
{
|
||||
int iRet;
|
||||
size_t cchMax = cchDest - 1;
|
||||
iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList);
|
||||
if ((iRet < 0) || (((size_t)iRet) > cchMax))
|
||||
{
|
||||
pszDestEnd = pszDest + cchMax;
|
||||
cchRemaining = 1;
|
||||
*pszDestEnd = L'\0';
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
}
|
||||
else if (((size_t)iRet) == cchMax)
|
||||
{
|
||||
pszDestEnd = pszDest + cchMax;
|
||||
cchRemaining = 1;
|
||||
*pszDestEnd = L'\0';
|
||||
}
|
||||
else if (((size_t)iRet) < cchMax)
|
||||
{
|
||||
pszDestEnd = pszDest + iRet;
|
||||
cchRemaining = cchDest - iRet;
|
||||
size_t cchDestNewLen = 0;
|
||||
|
||||
if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
|
||||
{
|
||||
memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
|
||||
}
|
||||
Status = RtlpArrayVPrintfWorkerW(pszDest, cchDest, pszFormat, &cchDestNewLen, argList);
|
||||
pszDestEnd = pszDest + cchDestNewLen;
|
||||
cchRemaining = cchDest - cchDestNewLen;
|
||||
|
||||
if (NT_SUCCESS(Status) && (dwFlags & STRSAFE_FILL_BEHIND) && cchRemaining)
|
||||
{
|
||||
memset(pszDestEnd, STRSAFE_GET_FILL_PATTERN(dwFlags), (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
|
||||
}
|
||||
|
||||
if (pcchDestNewLen)
|
||||
*pcchDestNewLen = iRet == -1 ? cchDest : iRet;
|
||||
*pcchDestNewLen = cchDestNewLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3120,6 +3099,7 @@ NTSTRSAFEAPI RtlpStringVPrintfExWorkerW(
|
|||
*pszDestEnd = L'\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
|
||||
{
|
||||
if (cchDest > 0)
|
||||
|
@ -3157,24 +3137,6 @@ NTSTRSAFEAPI RtlStringVPrintfExWorkerW(
|
|||
return RtlpStringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, NULL, argList);
|
||||
}
|
||||
|
||||
NTSTRSAFEAPI RtlStringVPrintfExWorkerLenW(
|
||||
STRSAFE_LPWSTR pszDest,
|
||||
size_t cchDest,
|
||||
size_t cbDest,
|
||||
STRSAFE_LPWSTR *ppszDestEnd,
|
||||
size_t *pcchRemaining,
|
||||
STRSAFE_DWORD dwFlags,
|
||||
STRSAFE_LPCWSTR pszFormat,
|
||||
size_t* pcchDestNewLen,
|
||||
va_list argList)
|
||||
{
|
||||
if (pcchDestNewLen == 0)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
return RtlpStringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, pcchDestNewLen, argList);
|
||||
}
|
||||
|
||||
|
||||
NTSTRSAFEAPI
|
||||
RtlStringLengthWorkerA(
|
||||
_In_reads_or_z_(cchMax) STRSAFE_LPCSTR psz,
|
||||
|
@ -3285,7 +3247,7 @@ RtlUnicodeStringPrintf(
|
|||
size_t cchFinalLength;
|
||||
va_list argList;
|
||||
|
||||
if (DestinationString == NULL || pszFormat == NULL || DestinationString->Buffer == NULL)
|
||||
if (DestinationString == NULL || pszFormat == NULL)
|
||||
{
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
@ -3296,7 +3258,7 @@ RtlUnicodeStringPrintf(
|
|||
{
|
||||
va_start(argList, pszFormat);
|
||||
|
||||
Status = RtlStringVPrintfWorkerLenW(DestinationString->Buffer,
|
||||
Status = RtlpArrayVPrintfWorkerW(DestinationString->Buffer,
|
||||
DestinationString->MaximumLength / sizeof(WCHAR),
|
||||
pszFormat,
|
||||
&cchFinalLength,
|
||||
|
@ -3328,7 +3290,7 @@ RtlUnicodeStringPrintfEx(
|
|||
|
||||
va_start(argList, pszFormat);
|
||||
|
||||
Status = RtlStringVPrintfExWorkerLenW(DestinationString->Buffer,
|
||||
Status = RtlpStringVPrintfExWorkerW(DestinationString->Buffer,
|
||||
DestinationString->MaximumLength / sizeof(WCHAR),
|
||||
DestinationString->MaximumLength,
|
||||
&RemainingString->Buffer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue