OSDN Git Service

Fix VS Code Analysis warnings (C6102)
authorsdottaka <sdottaka@users.sourceforge.net>
Sun, 24 May 2015 11:56:50 +0000 (20:56 +0900)
committersdottaka <sdottaka@users.sourceforge.net>
Sun, 24 May 2015 11:56:50 +0000 (20:56 +0900)
--HG--
branch : stable

Src/Common/ExConverter.cpp
Src/Common/Picture.cpp
Src/Common/SuperComboBox.cpp
Src/Common/version.cpp
Src/GhostTextView.cpp
Src/IListCtrlImpl.h
Src/JumpList.cpp
Src/Merge.cpp
Src/MergeApp.cpp
Src/dllpstub.cpp
Src/paths.cpp

index 0db11d6..f56c887 100644 (file)
@@ -228,7 +228,8 @@ public:
                if (FAILED(hr))
                        return 0;
                std::unique_ptr<MIMECPINFO[]> pcpInfo(new MIMECPINFO[count]);
-               pEnumCodePage->Next(count, pcpInfo.get(), &ccpInfo);
+               if (FAILED(pEnumCodePage->Next(count, pcpInfo.get(), &ccpInfo)))
+                       return 0;
 
                for (int i = 0; i < (int)ccpInfo; i++)
                {
index 0c64c51..1c90531 100644 (file)
@@ -129,8 +129,8 @@ CSize CPicture::GetImageSize(CDC* pDC) const
                return CSize(0,0);
        
        LONG hmWidth, hmHeight; // HIMETRIC units
-       m_spIPicture->get_Width(&hmWidth);
-       m_spIPicture->get_Height(&hmHeight);
+       if (FAILED(m_spIPicture->get_Width(&hmWidth)) || FAILED(m_spIPicture->get_Height(&hmHeight)))
+               return CSize(0, 0);
        CSize sz(hmWidth,hmHeight);
        if (pDC==NULL) {
                CWindowDC dc(NULL);
index 8ce444c..d9690e0 100644 (file)
@@ -481,11 +481,10 @@ void CSuperComboBox::OnGetDispInfo(NMHDR *pNotifyStruct, LRESULT *pResult)
        {
                pDispInfo->ceItem.mask |= CBEIF_DI_SETITEM;
                SHFILEINFO sfi = {0};
-               TCHAR szDrive[5] = {0};
                CString sText;
                GetLBText(static_cast<int>(pDispInfo->ceItem.iItem), sText);
-               lstrcpyn(szDrive, sText, 4);
-               if (sText[1] != '\\' && GetDriveType(szDrive) != DRIVE_REMOTE)
+               CString sDrive = sText.Left(3);
+               if (!(sText.GetLength() > 2 && (sText[1] == '\\' || GetDriveType(sDrive) == DRIVE_REMOTE)))
                {
                        // The path is not a network path.
                        if (SHGetFileInfo(sText, 0, &sfi, sizeof(sfi), 
index d7daeb1..5405a36 100644 (file)
@@ -289,7 +289,7 @@ void CVersionInfo::GetVersionInfo()
        {
                m_bVersionFound = TRUE;
                m_pVffInfo.reset(new BYTE[dwVerInfoSize]);
-               if (GetFileVersionInfo(szFileName, dwVerHnd, dwVerInfoSize, m_pVffInfo.get()))
+               if (GetFileVersionInfo(szFileName, 0, dwVerInfoSize, m_pVffInfo.get()))
                {
                        GetFixedVersionInfo();
                        if (m_bVersionOnly == FALSE)
index 671c1ab..d0f07f4 100644 (file)
@@ -263,7 +263,8 @@ HGLOBAL CGhostTextView::PrepareDragData ()
        ASSERT(::GlobalSize(hData) == cbData);
 
        LPTSTR pszData = (LPTSTR)::GlobalLock (hData);
-       memcpy (pszData, text, cbData);
+       if (pszData)
+               memcpy (pszData, text, cbData);
        ::GlobalUnlock (hData);
 
        m_ptDraggedTextBegin = m_ptDrawSelStart;
index 281f14e..f87e165 100644 (file)
@@ -78,39 +78,44 @@ public:
        std::string GetIconPNGData(int iconIndex) const
        {
                HIMAGELIST hImageList = ListView_GetImageList(m_hwndListCtrl, LVSIL_SMALL);
-               IMAGEINFO imageInfo = {0};
-               LARGE_INTEGER li = {0};
-               IStream *pStream = NULL;
-               CImage image;
-
-               ImageList_GetImageInfo(hImageList, iconIndex, &imageInfo);
-               int w = imageInfo.rcImage.right - imageInfo.rcImage.left;
-               int h = imageInfo.rcImage.bottom - imageInfo.rcImage.top;
-               CreateStreamOnHGlobal(NULL, TRUE, &pStream);
-               HDC hdcMem = CreateCompatibleDC(NULL);
-               BITMAPINFO bmpinfo = {0};
-               bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-               bmpinfo.bmiHeader.biWidth = w;
-               bmpinfo.bmiHeader.biHeight = h;
-               bmpinfo.bmiHeader.biPlanes = 1;
-               bmpinfo.bmiHeader.biBitCount = 32;
-               bmpinfo.bmiHeader.biCompression = BI_RGB;
-               HBITMAP hbmpImage = CreateDIBSection( NULL, &bmpinfo, DIB_RGB_COLORS, NULL, NULL, NULL);
-               HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpImage);
-               ImageList_Draw(hImageList, iconIndex, hdcMem, 0, 0, ILD_TRANSPARENT);
-               image.Attach(hbmpImage);
-               image.SetHasAlphaChannel(true);
-               image.Save(pStream, Gdiplus::ImageFormatPNG);
-               STATSTG stat;
-               pStream->Stat(&stat, STATFLAG_NONAME);
-               std::string ret(stat.cbSize.LowPart, 0);
-               pStream->Seek(li, STREAM_SEEK_SET, NULL);
-               pStream->Read(&ret[0], stat.cbSize.LowPart, NULL);
-               pStream->Release();
-
-               SelectObject(hdcMem, hbmpOld);
-               DeleteObject(hdcMem);
-               DeleteObject(hbmpImage);
+               IMAGEINFO imageInfo;
+               std::string ret;
+               if (ImageList_GetImageInfo(hImageList, iconIndex, &imageInfo))
+               {
+                       HDC hdcMem = CreateCompatibleDC(NULL);
+                       BITMAPINFO bmpinfo = { 0 };
+                       bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+                       int w = imageInfo.rcImage.right - imageInfo.rcImage.left;
+                       int h = imageInfo.rcImage.bottom - imageInfo.rcImage.top;
+                       bmpinfo.bmiHeader.biWidth = w;
+                       bmpinfo.bmiHeader.biHeight = h;
+                       bmpinfo.bmiHeader.biPlanes = 1;
+                       bmpinfo.bmiHeader.biBitCount = 32;
+                       bmpinfo.bmiHeader.biCompression = BI_RGB;
+                       HBITMAP hbmpImage = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, NULL, NULL, NULL);
+                       HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpImage);
+                       ImageList_Draw(hImageList, iconIndex, hdcMem, 0, 0, ILD_TRANSPARENT);
+                       CImage image;
+                       image.Attach(hbmpImage);
+                       image.SetHasAlphaChannel(true);
+                       IStream *pStream = NULL;
+                       if (SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pStream)))
+                       {
+                               image.Save(pStream, Gdiplus::ImageFormatPNG);
+                               STATSTG stat;
+                               if (SUCCEEDED(pStream->Stat(&stat, STATFLAG_NONAME)))
+                               {
+                                       LARGE_INTEGER li = {0};
+                                       ret.resize(0, stat.cbSize.LowPart);
+                                       pStream->Seek(li, STREAM_SEEK_SET, NULL);
+                                       pStream->Read(&ret[0], stat.cbSize.LowPart, NULL);
+                               }
+                               pStream->Release();
+                       }
+                       SelectObject(hdcMem, hbmpOld);
+                       DeleteObject(hdcMem);
+                       DeleteObject(hbmpImage);
+               }
                return ret;
        }
 
index fb7b7c9..e26cabe 100644 (file)
@@ -41,9 +41,11 @@ IShellLinkW *CreateShellLink(const std::wstring& app_path, const std::wstring& p
        if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
        {
                PROPVARIANT pv;
-               InitPropVariantFromString(title.c_str(), &pv);
-               pPS->SetValue(PKEY_Title, pv);
-               PropVariantClear(&pv);
+               if (SUCCEEDED(InitPropVariantFromString(title.c_str(), &pv)))
+               {
+                       pPS->SetValue(PKEY_Title, pv);
+                       PropVariantClear(&pv);
+               }
                pPS->Commit();
                pPS->Release();
        }
@@ -98,30 +100,33 @@ std::vector<Item> GetRecentDocs(size_t nMaxItems)
        if (SUCCEEDED(pDocumentLists->GetList(ADLT_RECENT, static_cast<UINT>(nMaxItems), IID_IObjectArray, (void **)&pObjectArray)))
        {
                UINT nObjects;
-               pObjectArray->GetCount(&nObjects);
-               for (UINT i = 0; i < nObjects; ++i)
+               if (SUCCEEDED(pObjectArray->GetCount(&nObjects)))
                {
-                       IShellLinkW *pShellLink;
-                       if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
+                       for (UINT i = 0; i < nObjects; ++i)
                        {
-                               wchar_t szPath[MAX_PATH];
-                               wchar_t szDescription[MAX_PATH];
-                               wchar_t szArguments[MAX_PATH * 6];
-                               pShellLink->GetPath(szPath, sizeof(szPath)/sizeof(szPath[0]), NULL, SLGP_RAWPATH);
-                               pShellLink->GetDescription(szDescription, sizeof(szDescription)/sizeof(szDescription[0]));
-                               pShellLink->GetArguments(szArguments, sizeof(szArguments)/sizeof(szArguments[0]));
-                               IPropertyStore *pPS = NULL;
-                               PROPVARIANT pv;
-                               InitPropVariantFromString(L"", &pv);
-                               if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
+                               IShellLinkW *pShellLink;
+                               if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
                                {
-                                       pPS->GetValue(PKEY_Title, &pv);
-                                       pPS->Release();
+                                       wchar_t szPath[MAX_PATH];
+                                       wchar_t szDescription[MAX_PATH];
+                                       wchar_t szArguments[MAX_PATH * 6];
+                                       pShellLink->GetPath(szPath, sizeof(szPath) / sizeof(szPath[0]), NULL, SLGP_RAWPATH);
+                                       pShellLink->GetDescription(szDescription, sizeof(szDescription) / sizeof(szDescription[0]));
+                                       pShellLink->GetArguments(szArguments, sizeof(szArguments) / sizeof(szArguments[0]));
+                                       IPropertyStore *pPS = NULL;
+                                       if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
+                                       {
+                                               PROPVARIANT pv;
+                                               if (SUCCEEDED(pPS->GetValue(PKEY_Title, &pv)))
+                                               {
+                                                       list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
+                                                       PropVariantClear(&pv);
+                                               }
+                                               pPS->Release();
+                                       }
+                                       pShellLink->Release();
                                }
-                               list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
-                               PropVariantClear(&pv);
-                               pShellLink->Release();
-                       }               
+                       }
                }
                pObjectArray->Release();
        }
index adca0f1..ddc660b 100644 (file)
@@ -363,13 +363,15 @@ BOOL CMergeApp::InitInstance()
        g_bPredifferMode = theApp.GetProfileInt(_T("Settings"), _T("PredifferMode"), PLUGIN_MANUAL);
 
        NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS };
-       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0);
-       HDC hdc = ::GetDC(NULL);
-       int lfHeight = -MulDiv(9, GetDeviceCaps(hdc, LOGPIXELSY), 72);
-       ::ReleaseDC(NULL, hdc);
-       if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight))
-               ncm.lfMenuFont.lfHeight = lfHeight;
-       m_fontGUI.CreateFontIndirect(&ncm.lfMenuFont);
+       if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0))
+       {
+               HDC hdc = ::GetDC(NULL);
+               int lfHeight = -MulDiv(9, GetDeviceCaps(hdc, LOGPIXELSY), 72);
+               ::ReleaseDC(NULL, hdc);
+               if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight))
+                       ncm.lfMenuFont.lfHeight = lfHeight;
+               m_fontGUI.CreateFontIndirect(&ncm.lfMenuFont);
+       }
 
        if (m_pSyntaxColors)
                Options::SyntaxColors::Load(m_pSyntaxColors.get());
index 6da8673..02920f8 100644 (file)
@@ -23,9 +23,9 @@ String GetSysError(int nerr /* =-1 */)
                ))
        {
                str = (LPCTSTR)lpMsgBuf;
+               // Free the buffer.
+               LocalFree( lpMsgBuf );
        }
-       // Free the buffer.
-       LocalFree( lpMsgBuf );
        return str;
 }
 
index d3b94c4..d426f73 100644 (file)
@@ -53,7 +53,7 @@ void DLLPSTUB::Throw(LPCSTR name, HMODULE handle, DWORD dwError, BOOL bFreeLibra
                szError[1] = '\n';
                strError += szError;
        }
-       if (bFreeLibrary)
+       if (bFreeLibrary && handle)
        {
                FreeLibrary(handle);
        }
index 296d967..2fe10f1 100644 (file)
@@ -13,6 +13,7 @@
 #include <shlwapi.h>
 #include "PathContext.h"
 #include "unicoder.h"
+#include "coretools.h"
 
 static bool IsSlash(const String& pszStart, size_t nPos);
 static bool GetDirName(const String& sDir, String& sName);
@@ -65,16 +66,15 @@ PATH_EXISTENCE paths_DoesPathExist(const String& szPath, bool (*IsArchiveFile)(c
 
        // Expand environment variables:
        // Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
-       const TCHAR *lpcszPath;
-       TCHAR expandedPath[_MAX_PATH] = {0};
+       const TCHAR *lpcszPath = szPath.c_str();
+       TCHAR expandedPath[_MAX_PATH];
 
-       if (_tcschr(szPath.c_str(), '%') &&
-               ExpandEnvironmentStrings(szPath.c_str(), expandedPath, _MAX_PATH))
+       if (_tcschr(lpcszPath, '%'))
        {
-               lpcszPath = expandedPath;
+               DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, _MAX_PATH);
+               if (dwLen > 0 && dwLen < _MAX_PATH)
+                       lpcszPath = expandedPath;
        }
-       else
-               lpcszPath = szPath.c_str();
 
        DWORD attr = GetFileAttributes(lpcszPath);
 
@@ -210,21 +210,18 @@ String paths_GetLongPath(const String& szPath, bool bExpandEnvs)
 
        // Expand environment variables:
        // Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
-       TCHAR expandedPath[_MAX_PATH] = {0};
-       const TCHAR *lpcszPath = NULL;
-
-       if (bExpandEnvs && _tcschr(sPath.c_str(), '%'))
+       TCHAR expandedPath[_MAX_PATH];
+       const TCHAR *lpcszPath = sPath.c_str();
+       if (bExpandEnvs && _tcschr(lpcszPath, '%'))
        {
-               if (ExpandEnvironmentStrings(sPath.c_str(), expandedPath, _MAX_PATH))
-               {
+               DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, _MAX_PATH);
+               if (dwLen > 0 && dwLen < _MAX_PATH)
                        lpcszPath = expandedPath;
-               }
        }
-       else
-               lpcszPath = sPath.c_str();
 
-       if (!GetFullPathName(lpcszPath, _MAX_PATH, fullPath, &lpPart))
-               _tcscpy(fullPath, sPath.c_str());
+       DWORD dwLen = GetFullPathName(lpcszPath, _MAX_PATH, fullPath, &lpPart);
+       if (dwLen == 0 || dwLen >= _MAX_PATH)
+               _tcscpy_safe(fullPath, lpcszPath);
 
        // We are done if this is not a short name.
        if (_tcschr(fullPath, _T('~')) == NULL)
@@ -312,11 +309,15 @@ bool paths_CreateIfNeeded(const String& szPath)
 
        // Expand environment variables:
        // Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
-       TCHAR fullPath[_MAX_PATH] = _T("");
-       if (!_tcschr(szPath.c_str(), '%') || !ExpandEnvironmentStrings(szPath.c_str(), fullPath, _MAX_PATH))
+       TCHAR fullPath[_MAX_PATH];
+       if (_tcschr(szPath.c_str(), '%'))
        {
-               _tcscpy(fullPath, szPath.c_str());
+               DWORD dwLen = ExpandEnvironmentStrings(szPath.c_str(), fullPath, _MAX_PATH);
+               if (dwLen == 0 || dwLen >= _MAX_PATH)
+                       _tcscpy_safe(fullPath, szPath.c_str());
        }
+       else
+               _tcscpy_safe(fullPath, szPath.c_str());
        // Now fullPath holds our desired path
 
        TCHAR *ptr = fullPath;
@@ -457,7 +458,7 @@ String ExpandShortcut(const String &inFile)
                {
                        WCHAR wsz[MAX_PATH];
 #ifdef _UNICODE
-                       wcsncpy((wchar_t *)wsz, inFile.c_str(), sizeof(wsz) / sizeof(WCHAR));
+                       _tcscpy_safe(wsz, inFile.c_str());
 #else
                        ::MultiByteToWideChar(CP_ACP, 0, inFile.c_str(), -1, wsz, MAX_PATH);
 #endif