From db58e3f45a11aa0b19c5d0638a20cc5d404f40a6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 13 Jul 2014 17:25:52 +0000 Subject: more code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@9789 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/addcontact/addcontact.cpp | 45 +++++++++++++++++------------------ src/modules/netlib/netlibbind.cpp | 16 ++++--------- 2 files changed, 26 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/modules/addcontact/addcontact.cpp b/src/modules/addcontact/addcontact.cpp index 5742a90402..3a98550715 100644 --- a/src/modules/addcontact/addcontact.cpp +++ b/src/modules/addcontact/addcontact.cpp @@ -237,30 +237,29 @@ INT_PTR CALLBACK AddContactDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lp INT_PTR AddContactDialog(WPARAM wParam, LPARAM lParam) { - if (lParam) { - ADDCONTACTSTRUCT* acs = (ADDCONTACTSTRUCT*)mir_alloc(sizeof(ADDCONTACTSTRUCT)); - memmove(acs, (ADDCONTACTSTRUCT*)lParam, sizeof(ADDCONTACTSTRUCT)); - if (acs->psr) { - PROTOSEARCHRESULT *psr; - /* bad! structures that are bigger than psr will cause crashes if they define pointers within unreachable structural space */ - psr = (PROTOSEARCHRESULT *)mir_alloc(acs->psr->cbSize); - memmove(psr, acs->psr, acs->psr->cbSize); - psr->nick = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->nick) : mir_a2t((char*)psr->nick); - psr->firstName = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->firstName) : mir_a2t((char*)psr->firstName); - psr->lastName = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->lastName) : mir_a2t((char*)psr->lastName); - psr->email = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->email) : mir_a2t((char*)psr->email); - psr->flags = psr->flags & ~PSR_UNICODE | PSR_TCHAR; - acs->psr = psr; - /* copied the passed acs structure, the psr structure with, the pointers within that */ - } - - if (wParam) - DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ADDCONTACT), (HWND)wParam, AddContactDlgProc, (LPARAM)acs); - else - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDCONTACT), (HWND)wParam, AddContactDlgProc, (LPARAM)acs); - return 0; + if (lParam == 0) + return 1; + + ADDCONTACTSTRUCT *acs = (ADDCONTACTSTRUCT*)mir_alloc(sizeof(ADDCONTACTSTRUCT)); + memmove(acs, (ADDCONTACTSTRUCT*)lParam, sizeof(ADDCONTACTSTRUCT)); + if (acs->psr) { + // bad! structures that are bigger than psr will cause crashes if they define pointers within unreachable structural space + PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT*)mir_alloc(acs->psr->cbSize); + memmove(psr, acs->psr, acs->psr->cbSize); + psr->nick = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->nick) : mir_a2t((char*)psr->nick); + psr->firstName = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->firstName) : mir_a2t((char*)psr->firstName); + psr->lastName = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->lastName) : mir_a2t((char*)psr->lastName); + psr->email = psr->flags & PSR_UNICODE ? mir_u2t((wchar_t*)psr->email) : mir_a2t((char*)psr->email); + psr->flags = psr->flags & ~PSR_UNICODE | PSR_TCHAR; + acs->psr = psr; + /* copied the passed acs structure, the psr structure with, the pointers within that */ } - return 1; + + if (wParam) + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ADDCONTACT), (HWND)wParam, AddContactDlgProc, (LPARAM)acs); + else + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDCONTACT), (HWND)wParam, AddContactDlgProc, (LPARAM)acs); + return 0; } int LoadAddContactModule(void) diff --git a/src/modules/netlib/netlibbind.cpp b/src/modules/netlib/netlibbind.cpp index 4d5e7b6ca8..00aef09049 100644 --- a/src/modules/netlib/netlibbind.cpp +++ b/src/modules/netlib/netlibbind.cpp @@ -243,6 +243,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) } if (!foundPort) { NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "bind", WSAGetLastError()); +LBL_Error: closesocket(nlbp->s); closesocket(nlbp->s6); mir_free(nlbp); @@ -251,18 +252,12 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) if (nlbp->s != INVALID_SOCKET && listen(nlbp->s, 5)) { NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "listen", WSAGetLastError()); - closesocket(nlbp->s); - closesocket(nlbp->s6); - mir_free(nlbp); - return 0; + goto LBL_Error; } if (nlbp->s6 != INVALID_SOCKET && listen(nlbp->s6, 5)) { NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "listen", WSAGetLastError()); - closesocket(nlbp->s); - closesocket(nlbp->s6); - mir_free(nlbp); - return 0; + goto LBL_Error; } SOCKADDR_INET_M sinm = { 0 }; @@ -275,10 +270,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam) nlb->wPort = ntohs(sinm.Ipv6.sin6_port); else { NetlibLogf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "getsockname", WSAGetLastError()); - closesocket(nlbp->s); - closesocket(nlbp->s6); - mir_free(nlbp); - return 0; + goto LBL_Error; } nlbp->wPort = nlb->wPort; -- cgit v1.2.3