Index: src/ch/DirTreeCtrl.cpp =================================================================== diff -u -r90e8a7720fc23cf282e486c7b2bc1dc590b5d74c -r86c2327549cd4fa98972cf9035f9a78451a00f88 --- src/ch/DirTreeCtrl.cpp (.../DirTreeCtrl.cpp) (revision 90e8a7720fc23cf282e486c7b2bc1dc590b5d74c) +++ src/ch/DirTreeCtrl.cpp (.../DirTreeCtrl.cpp) (revision 86c2327549cd4fa98972cf9035f9a78451a00f88) @@ -57,38 +57,33 @@ LPITEMIDLIST CreatePidl(UINT cbSize) { - LPMALLOC lpMalloc; - HRESULT hr; - LPITEMIDLIST pidl=nullptr; + LPMALLOC lpMalloc = nullptr; - hr=SHGetMalloc(&lpMalloc); + HRESULT hr=SHGetMalloc(&lpMalloc); + if (FAILED(hr) || !lpMalloc) + return nullptr; - if (FAILED(hr)) - return 0; - - pidl=(LPITEMIDLIST)lpMalloc->Alloc(cbSize); - + LPITEMIDLIST pidl = (LPITEMIDLIST)lpMalloc->Alloc(cbSize); if (pidl) memset(pidl, 0, cbSize); // zero-init for external task alloc - if (lpMalloc) lpMalloc->Release(); + lpMalloc->Release(); return pidl; } void FreePidl(LPITEMIDLIST lpiidl) { - LPMALLOC lpMalloc; - HRESULT hr; - - hr=SHGetMalloc(&lpMalloc); - - if (FAILED(hr)) + if(!lpiidl) return; - lpMalloc->Free(lpiidl); + LPMALLOC lpMalloc = nullptr; + HRESULT hResult = SHGetMalloc(&lpMalloc); + if(SUCCEEDED(hResult) && lpMalloc) + lpMalloc->Free(lpiidl); - if (lpMalloc) lpMalloc->Release(); + if (lpMalloc) + lpMalloc->Release(); } LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) @@ -409,7 +404,7 @@ tvis.item=tvi; hCurrent=InsertItem(&tvis); - if (hParent == GetRootItem()) + if (hParent == GetRootItem() && lpsfDesktop) { // if this is My computer or net. neigh. - it's better to remember the handles // compare psid->lpiidl and (lpiidlDrives & lpiidlNetwork) Index: src/libchcore/TWin32ErrorFormatter.cpp =================================================================== diff -u -ra6fac511b0dd40e1c18cab086e0bc5ff5d2bc8d7 -r86c2327549cd4fa98972cf9035f9a78451a00f88 --- src/libchcore/TWin32ErrorFormatter.cpp (.../TWin32ErrorFormatter.cpp) (revision a6fac511b0dd40e1c18cab086e0bc5ff5d2bc8d7) +++ src/libchcore/TWin32ErrorFormatter.cpp (.../TWin32ErrorFormatter.cpp) (revision 86c2327549cd4fa98972cf9035f9a78451a00f88) @@ -43,17 +43,18 @@ TString strData; wchar_t* pszBuffer = strData.GetBuffer(dwMaxError); - DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM; - if (hModule) - dwFlags |= FORMAT_MESSAGE_FROM_HMODULE; + DWORD dwPos = 0; + if(hModule) + dwPos = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, hModule, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), pszBuffer, dwMaxError - 1, NULL); + else + dwPos = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), pszBuffer, dwMaxError - 1, NULL); - DWORD dwPos = FormatMessage(dwFlags, hModule, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), pszBuffer, dwMaxError - 1, NULL); if (dwPos == 0xffffffff) { int iPos = 0; if (bUseNumberFallback) iPos = _sntprintf_s(pszBuffer, dwMaxError, _TRUNCATE, _T("ErrorCode: 0x%lx"), dwErrorCode); - strData.ReleaseBufferSetLength(iPos); + strData.ReleaseBufferSetLength(iPos < 0 ? 0 : iPos); } else strData.ReleaseBufferSetLength(std::min(dwPos, dwMaxError - 1));