From: Hermès Bélusca-Maïto Date: Sat, 4 Mar 2017 01:09:28 +0000 (+0000) Subject: [WS2_32] X-Git-Tag: ReactOS-0.4.4-CLT2017~46 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=f752d4ffda87308e6059af949ebd78e2f05526ab [WS2_32] - 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 --- diff --git a/reactos/dll/win32/ws2_32/src/dcatalog.c b/reactos/dll/win32/ws2_32/src/dcatalog.c index a32aa65056b..6daa7abcd39 100644 --- a/reactos/dll/win32/ws2_32/src/dcatalog.c +++ b/reactos/dll/win32/ws2_32/src/dcatalog.c @@ -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 */ diff --git a/reactos/dll/win32/ws2_32/src/nscatalo.c b/reactos/dll/win32/ws2_32/src/nscatalo.c index d1290c71e85..3bcb6e70fa5 100644 --- a/reactos/dll/win32/ws2_32/src/nscatalo.c +++ b/reactos/dll/win32/ws2_32/src/nscatalo.c @@ -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 */ diff --git a/reactos/dll/win32/ws2_32/src/nsquery.c b/reactos/dll/win32/ws2_32/src/nsquery.c index c56066c527c..b67c837d3aa 100644 --- a/reactos/dll/win32/ws2_32/src/nsquery.c +++ b/reactos/dll/win32/ws2_32/src/nsquery.c @@ -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) { diff --git a/reactos/dll/win32/ws2_32/src/qshelpr.c b/reactos/dll/win32/ws2_32/src/qshelpr.c index 9354c69ba93..48b31121382 100644 --- a/reactos/dll/win32/ws2_32/src/qshelpr.c +++ b/reactos/dll/win32/ws2_32/src/qshelpr.c @@ -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);