Commit add6726c authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Fix NetApiBufferReallocate and add a few tests for the border cases

(thanks to Juan Lang for clarifications).
parent 793bce5c
......@@ -60,11 +60,17 @@ NET_API_STATUS WINAPI NetApiBufferReallocate(LPVOID OldBuffer, DWORD NewByteCoun
LPVOID* NewBuffer)
{
TRACE("(%p, %ld, %p)\n", OldBuffer, NewByteCount, NewBuffer);
*NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount);
if (*NewBuffer)
return NERR_Success;
else
return GetLastError();
if (NewByteCount)
{
*NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount);
return *NewBuffer ? NERR_Success : GetLastError();
}
else
{
if (!HeapFree(GetProcessHeap(), 0, OldBuffer)) return GetLastError();
*NewBuffer = 0;
return NERR_Success;
}
}
/************************************************************
......
......@@ -63,7 +63,14 @@ void run_apibuf_tests(void)
ok(dwSize >= 0, "The size");
ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer");
/* 0-length buffer */
/* border reallocate cases */
ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) != NERR_Success, "(Re)allocated");
ok(p == NULL, "Some memory got allocated");
ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, "Memory not reserved");
ok(pNetApiBufferReallocate(p, 0, (LPVOID *) &p) == NERR_Success, "Not freed");
ok(p == NULL, "Pointer not cleared");
/* 0-length buffer */
ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
"Reserved memory");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment