mirror of
https://github.com/reactos/reactos.git
synced 2025-01-06 06:20:13 +00:00
[SPOOLSS]
Add ASSERTs, improve documentation and the variety of tests for AlignRpcPtr/UndoAlignRpcPtr. Based on comments by Serge Gautherie. svn path=/trunk/; revision=74323
This commit is contained in:
parent
c447bed85d
commit
c860e2b80d
2 changed files with 15 additions and 5 deletions
|
@ -28,6 +28,8 @@
|
|||
PVOID WINAPI
|
||||
AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
|
||||
{
|
||||
ASSERT(pcbBuffer);
|
||||
|
||||
// Align down the buffer size in pcbBuffer to a 4-byte boundary.
|
||||
*pcbBuffer -= *pcbBuffer % sizeof(DWORD);
|
||||
|
||||
|
@ -209,7 +211,7 @@ ReallocSplStr(PWSTR* ppwszString, PCWSTR pwszInput)
|
|||
* The original unaligned buffer, which you input as pBuffer to AlignRpcPtr.
|
||||
* The data from pSourceBuffer is copied into this buffer before pSourceBuffer is freed.
|
||||
* If AlignRpcPtr did not allocate a buffer, pDestinationBuffer equals pSourceBuffer and no memory is copied or freed.
|
||||
* This parameter may be NULL if pSourceBuffer is NULL.
|
||||
* This parameter may be NULL if pSourceBuffer is NULL or cbBuffer is 0.
|
||||
*
|
||||
* @param pSourceBuffer
|
||||
* The aligned buffer, which is returned by AlignRpcPtr.
|
||||
|
@ -233,6 +235,9 @@ ReallocSplStr(PWSTR* ppwszString, PCWSTR pwszInput)
|
|||
PDWORD WINAPI
|
||||
UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
|
||||
{
|
||||
// pDestinationBuffer is accessed unless pSourceBuffer equals pDestinationBuffer or cbBuffer is 0.
|
||||
ASSERT(pDestinationBuffer || pSourceBuffer == pDestinationBuffer || cbBuffer == 0);
|
||||
|
||||
// If pSourceBuffer is given, and source and destination pointers don't match,
|
||||
// we assume that pSourceBuffer is the buffer allocated by AlignRpcPtr.
|
||||
if (pSourceBuffer && pSourceBuffer != pDestinationBuffer)
|
||||
|
|
|
@ -54,13 +54,18 @@ START_TEST(AlignRpcPtr)
|
|||
ok(pOutputBuffer != pInputBuffer, "pOutputBuffer == pInputBuffer\n");
|
||||
ok(cbBuffer == 4, "cbBuffer is %lu\n", cbBuffer);
|
||||
|
||||
// Prove that AlignRpcPtr also works with a NULL buffer. The size should be aligned down.
|
||||
cbBuffer = 6;
|
||||
ok(!AlignRpcPtr(NULL, &cbBuffer), "AlignRpcPtr returns something\n");
|
||||
ok(cbBuffer == 4, "cbBuffer is %lu\n", cbBuffer);
|
||||
|
||||
// We can also test all parameters of UndoAlignRpcPtr here.
|
||||
// Because pOutputBuffer != pInputBuffer, it copies the given 4 bytes from (aligned) pOutputBuffer to (unaligned) pInputBuffer
|
||||
// while aligning up the given 7 bytes in our passed &cbBuffer.
|
||||
// &cbBuffer is also returned.
|
||||
strcpy(pOutputBuffer, "abc");
|
||||
strcpy(pInputBuffer, "XXXXXXXXX");
|
||||
cbBuffer = 7;
|
||||
cbBuffer = 5;
|
||||
pcbBuffer = UndoAlignRpcPtr(pInputBuffer, pOutputBuffer, 4, &cbBuffer);
|
||||
ok(strcmp(pInputBuffer, "abc") == 0, "pInputBuffer is %s\n", pInputBuffer);
|
||||
ok(pcbBuffer == &cbBuffer, "pcbBuffer != &cbBuffer\n");
|
||||
|
@ -68,14 +73,14 @@ START_TEST(AlignRpcPtr)
|
|||
|
||||
// Prove that UndoAlignRpcPtr works without any parameters and doesn't try to copy data from NULL pointers.
|
||||
ok(!UndoAlignRpcPtr(NULL, NULL, 0, NULL), "UndoAlignRpcPtr returns something\n");
|
||||
ok(!UndoAlignRpcPtr(NULL, NULL, 4, NULL), "UndoAlignRpcPtr returns something\n");
|
||||
ok(!UndoAlignRpcPtr(NULL, NULL, 6, NULL), "UndoAlignRpcPtr returns something\n");
|
||||
|
||||
// Prove that UndoAlignRpcPtr doesn't access source and destination memory at all when they are equal.
|
||||
// If it did, it should crash here, because I'm giving invalid memory addresses.
|
||||
ok(!UndoAlignRpcPtr((PVOID)1, (PVOID)1, 4, NULL), "UndoAlignRpcPtr returns something\n");
|
||||
|
||||
// Prove that the pcbNeeded parameter of UndoAlignRpcPtr works independently and aligns up everything up to a DWORD.
|
||||
cbBuffer = 0xFFFFFFFF;
|
||||
// Prove that the pcbNeeded parameter of UndoAlignRpcPtr works independently and aligns up to a DWORD.
|
||||
cbBuffer = 0xFFFFFFFD;
|
||||
pcbBuffer = UndoAlignRpcPtr(NULL, NULL, 0, &cbBuffer);
|
||||
ok(pcbBuffer == &cbBuffer, "pcbBuffer != &cbBuffer\n");
|
||||
ok(cbBuffer == 0, "cbBuffer is %lu\n", cbBuffer);
|
||||
|
|
Loading…
Reference in a new issue