OSDN Git Service

Fix Code scanning alert: Multiplication result converted to larger type
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 19 Feb 2023 07:28:05 +0000 (16:28 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 19 Feb 2023 07:28:05 +0000 (16:28 +0900)
Externals/crystaledit/editlib/utils/hqbitmap.cpp
Src/Common/BCMenu.cpp

index a4bb850..7264c44 100644 (file)
@@ -118,7 +118,8 @@ HBITMAP LoadBitmapAndConvertTo32bit(HINSTANCE hInstance, int nIDResource, int nN
        img.Attach((HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(nIDResource), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION), ATL::CImage::DIBOR_TOPDOWN);
        const int nWidth = img.GetWidth();
        const int nHeight= img.GetHeight();
-       const int stride = (nWidth * 4 * 4 + 3) / 4; std::vector<BYTE> buf(stride * nHeight);
+       const int stride = (nWidth * 4 * 4 + 3) / 4;
+       std::vector<BYTE> buf(static_cast<size_t>(stride) * nHeight);
        switch (img.GetBPP())
        {
        case 24:
index 8cbd00b..fb65d61 100644 (file)
@@ -109,7 +109,7 @@ static pBGR MyGetDibBits(HDC hdcSrc, HBITMAP hBmpSrc, int nx, int ny)
        bi.bmiHeader.biClrUsed = 0;
        bi.bmiHeader.biClrImportant = 0;
        
-       buf = (pBGR) malloc(nx * 4 * ny);
+       buf = (pBGR) malloc(static_cast<size_t>(nx) * 4 * ny);
        nRes = GetDIBits(hdcSrc, hBmpSrc, 0, ny, buf, &bi, DIB_RGB_COLORS);
        if (nRes == 0) {
                free(buf);
@@ -622,7 +622,7 @@ bool BCMenu::GetBitmapFromImageList(CDC* pDC,int nIndex,CImage &bmp)
        CDC dc;
        dc.CreateCompatibleDC(pDC);
        bmp.Create(m_iconX, -m_iconY, 32, CImage::createAlphaChannel);
-       memset(bmp.GetBits(), 0xff, abs(bmp.GetPitch()) * m_iconY);
+       memset(bmp.GetBits(), 0xff, static_cast<size_t>(abs(bmp.GetPitch())) * m_iconY);
        HGDIOBJ pOldBmp = dc.SelectObject(bmp.operator HBITMAP());
        POINT pt = {0};
        SIZE  sz = {m_iconX, m_iconY};