- Turn the "!memcmp(ptr1, ptr2, sizeof(GUID))" into IsEqualGUID(ptr1, ptr2) macro calls (aka. make code readable);
  this also allowed me to discover a logical bug in the GUID comparison in WsNcUpdateNamespaceList.
- Fix few comments, and rename some goto labels to make their meaning clearer (they are not only taken for error code paths,
  but also on regular path, for cleanup before returning from the function).
CORE-12880

svn path=/trunk/; revision=74045
This commit is contained in:
Hermès Bélusca-Maïto 2017-03-04 01:09:28 +00:00
parent 99e8525cb3
commit f752d4ffda
4 changed files with 30 additions and 37 deletions

View file

@ -591,10 +591,8 @@ WsTcFindProvider(IN PTCATALOG Catalog,
Provider = CatalogEntry->Provider;
/* Check for a match */
if ((Provider) &&
!(memcmp(&CatalogEntry->ProtocolInfo.ProviderId,
ProviderId,
sizeof(GUID))))
if (Provider &&
IsEqualGUID(&CatalogEntry->ProtocolInfo.ProviderId, ProviderId))
{
/* Found a match */
return Provider;
@ -879,10 +877,8 @@ WsTcDelete(IN PTCATALOG Catalog)
/* Get this entry */
CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
/* Remove it */
/* Remove it and dereference it */
WsTcRemoveCatalogItem(Catalog, CatalogEntry);
/* Dereference it */
WsTcEntryDereference(CatalogEntry);
/* Move to the next entry */

View file

@ -459,9 +459,8 @@ WsNcUpdateNamespaceList(IN PNSCATALOG Catalog,
Entry = Entry->Flink;
/* Check if they match */
if (memcmp(&CatalogEntry->ProviderId,
&OldCatalogEntry->ProviderId,
sizeof(GUID)))
if (IsEqualGUID(&CatalogEntry->ProviderId,
&OldCatalogEntry->ProviderId))
{
/* We have a match, use the old item instead */
WsNcEntryDereference(CatalogEntry);
@ -513,7 +512,7 @@ WsNcGetCatalogFromProviderId(IN PNSCATALOG Catalog,
NextEntry = NextEntry->Flink;
/* Check if this is the Catalog Entry ID we want */
if (!(memcmp(&Entry->ProviderId, ProviderId, sizeof(GUID))))
if (IsEqualGUID(&Entry->ProviderId, ProviderId))
{
/* Check if it doesn't already have a provider */
if (!Entry->Provider)
@ -619,10 +618,8 @@ WsNcDelete(IN PNSCATALOG Catalog)
/* Get this entry */
CatalogEntry = CONTAINING_RECORD(Entry, NSCATALOG_ENTRY, CatalogLink);
/* Remove it */
/* Remove it and dereference it */
WsNcRemoveCatalogItem(Catalog, CatalogEntry);
/* Dereference it */
WsNcEntryDereference(CatalogEntry);
/* Move to the next entry */

View file

@ -373,7 +373,7 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
SetLastError(ErrorCode);
ErrorCode = SOCKET_ERROR;
NsQuery->TryAgain = FALSE;
goto error;
goto Exit;
}
/* Cache the information for a restart */
@ -384,17 +384,17 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
/* Check if we have a specific ID */
if (Restrictions->lpNSProviderId)
{
/* Get the provider */
/* Get the catalog entry */
ErrorCode = WsNcGetCatalogFromProviderId(Catalog,
Restrictions->lpNSProviderId,
&CatalogEntry);
/* Check for success */
/* Check for failure */
if (ErrorCode != ERROR_SUCCESS)
{
/* Fail */
SetLastError(WSAEINVAL);
ErrorCode = SOCKET_ERROR;
goto error;
goto Exit;
}
else
{
@ -422,7 +422,7 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
/* Fail */
SetLastError(WSAEINVAL);
ErrorCode = SOCKET_ERROR;
goto error;
goto Exit;
}
}
@ -447,7 +447,7 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
/* We don't have any providers to handle this! */
ErrorCode = SOCKET_ERROR;
SetLastError(WSASERVICE_NOT_FOUND);
goto error;
goto Exit;
}
/* Get the first provider and loop */
@ -476,7 +476,7 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
}
}
error:
Exit:
/* Check if we had an error somewhere */
if (ErrorCode == SOCKET_ERROR)
{

View file

@ -823,12 +823,12 @@ MapAnsiQuerySetToUnicode(IN LPWSAQUERYSETA AnsiSet,
{
/* Fail, couldn't allocate memory */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Build the relative buffer version */
ErrorCode = WSABuildQuerySetBufferA(AnsiSet, AnsiSize, AnsiCopy);
if (ErrorCode != ERROR_SUCCESS) goto error;
if (ErrorCode != ERROR_SUCCESS) goto Exit;
/* Re-use the ANSI version since the fields match */
UnicodeCopy = (LPWSAQUERYSETW)AnsiCopy;
@ -842,7 +842,7 @@ MapAnsiQuerySetToUnicode(IN LPWSAQUERYSETA AnsiSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -858,7 +858,7 @@ MapAnsiQuerySetToUnicode(IN LPWSAQUERYSETA AnsiSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -874,7 +874,7 @@ MapAnsiQuerySetToUnicode(IN LPWSAQUERYSETA AnsiSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -890,7 +890,7 @@ MapAnsiQuerySetToUnicode(IN LPWSAQUERYSETA AnsiSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -904,13 +904,13 @@ MapAnsiQuerySetToUnicode(IN LPWSAQUERYSETA AnsiSet,
/* The buffer wasn't large enough; return how much we need */
*SetSize = UnicodeSize;
ErrorCode = WSAEFAULT;
goto error;
goto Exit;
}
/* Build the relative unicode buffer */
ErrorCode = WSABuildQuerySetBufferW(UnicodeCopy, *SetSize, UnicodeSet);
error:
Exit:
/* Free the Ansi copy if we had one */
if (AnsiCopy) HeapFree(WsSockHeap, 0, AnsiCopy);
@ -944,12 +944,12 @@ MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
{
/* Fail, couldn't allocate memory */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Build the relative buffer version */
ErrorCode = WSABuildQuerySetBufferW(UnicodeSet, UnicodeSize, UnicodeCopy);
if (ErrorCode != ERROR_SUCCESS) goto error;
if (ErrorCode != ERROR_SUCCESS) goto Exit;
/* Re-use the Unicode version since the fields match */
AnsiCopy = (LPWSAQUERYSETA)UnicodeCopy;
@ -963,7 +963,7 @@ MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -979,7 +979,7 @@ MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -995,7 +995,7 @@ MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -1011,7 +1011,7 @@ MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
goto error;
goto Exit;
}
/* Set the new string pointer */
@ -1025,13 +1025,13 @@ MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
/* The buffer wasn't large enough; return how much we need */
*SetSize = AnsiSize;
ErrorCode = WSAEFAULT;
goto error;
goto Exit;
}
/* Build the relative unicode buffer */
ErrorCode = WSABuildQuerySetBufferA(AnsiCopy, *SetSize, AnsiSet);
error:
Exit:
/* Free the Ansi copy if we had one */
if (UnicodeCopy) HeapFree(WsSockHeap, 0, UnicodeCopy);