From 75ea06cec7356d474268e213f00c432751e61946 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Thu, 19 Apr 2018 20:02:52 +0700 Subject: [PATCH] Code refactoring: fix issues found by static code analizer. --- src/BufferCopy/ColorBufferToRDRAM.cpp | 3 +- src/BufferCopy/RDRAMtoColorBuffer.cpp | 14 +++++----- .../glsl_CombinerProgramUniformFactory.cpp | 2 +- src/TextDrawer.cpp | 2 +- src/Textures.cpp | 28 ++++++++++--------- src/uCodes/T3DUX.cpp | 11 +++++--- src/uCodes/ZSortBOSS.cpp | 4 +++ 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/BufferCopy/ColorBufferToRDRAM.cpp b/src/BufferCopy/ColorBufferToRDRAM.cpp index 84cbc8a5..50996fd7 100644 --- a/src/BufferCopy/ColorBufferToRDRAM.cpp +++ b/src/BufferCopy/ColorBufferToRDRAM.cpp @@ -307,7 +307,8 @@ void ColorBufferToRDRAM::_copy(u32 _startAddress, u32 _endAddress, bool _sync) u32 ColorBufferToRDRAM::_getRealWidth(u32 _viWidth) { u32 index = 0; - while(index < m_allowedRealWidths.size() && _viWidth > m_allowedRealWidths[index]) + const u32 maxIndex = m_allowedRealWidths.size() - 1; + while (index < maxIndex && _viWidth > m_allowedRealWidths[index]) { ++index; } diff --git a/src/BufferCopy/RDRAMtoColorBuffer.cpp b/src/BufferCopy/RDRAMtoColorBuffer.cpp index 48965d0f..dfba5515 100644 --- a/src/BufferCopy/RDRAMtoColorBuffer.cpp +++ b/src/BufferCopy/RDRAMtoColorBuffer.cpp @@ -207,30 +207,30 @@ void RDRAMtoColorBuffer::copyFromRDRAM(u32 _address, bool _bCFB) m_pTexture->width = width; m_pTexture->height = height; - u32 * dst = nullptr; + u32 * pDst = nullptr; std::unique_ptr dstData; //If not using float, the initial coversion will already be correct if (fbTexFormats.colorType == datatype::FLOAT) { const u32 initialDataSize = width*height * 4; dstData = std::unique_ptr(new u8[initialDataSize]); - dst = reinterpret_cast(dstData.get()); + pDst = reinterpret_cast(dstData.get()); } else { - dst = reinterpret_cast(m_pbuf); + pDst = reinterpret_cast(m_pbuf); } bool bCopy; if (m_vecAddress.empty()) { if (m_pCurBuffer->m_size == G_IM_SIZ_16b) - bCopy = _copyBufferFromRdram(address, dst, RGBA16ToABGR32, 1, x0, y0, width, height, _bCFB); + bCopy = _copyBufferFromRdram(address, pDst, RGBA16ToABGR32, 1, x0, y0, width, height, _bCFB); else - bCopy = _copyBufferFromRdram(address, dst, RGBA32ToABGR32, 0, x0, y0, width, height, _bCFB); + bCopy = _copyBufferFromRdram(address, pDst, RGBA32ToABGR32, 0, x0, y0, width, height, _bCFB); } else { if (m_pCurBuffer->m_size == G_IM_SIZ_16b) - bCopy = _copyPixelsFromRdram(address, m_vecAddress, dst, RGBA16ToABGR32, 1, width, height, _bCFB); + bCopy = _copyPixelsFromRdram(address, m_vecAddress, pDst, RGBA16ToABGR32, 1, width, height, _bCFB); else - bCopy = _copyPixelsFromRdram(address, m_vecAddress, dst, RGBA32ToABGR32, 0, width, height, _bCFB); + bCopy = _copyPixelsFromRdram(address, m_vecAddress, pDst, RGBA32ToABGR32, 0, width, height, _bCFB); } //Convert integer format to float diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp index 683a80b7..d18b4f1b 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp @@ -679,7 +679,7 @@ public: void update(bool _force) override { - int clampMode; + int clampMode = -1; switch (gfxContext.getClampMode()) { case graphics::ClampMode::ClippingEnabled: diff --git a/src/TextDrawer.cpp b/src/TextDrawer.cpp index 583aad47..7823ac70 100644 --- a/src/TextDrawer.cpp +++ b/src/TextDrawer.cpp @@ -372,7 +372,7 @@ void TextDrawer::getTextSize(const char *_pText, float & _w, float & _h) const DisplayWindow & wnd = DisplayWindow::get(); const float sx = 2.0f / wnd.getWidth(); const float sy = 2.0f / wnd.getHeight(); - float bw, bh = 0; + float bw = 0, bh = 0; for (const u8 *p = (const u8 *)_pText; *p; ++p) { bw = m_atlas->c[*p].bw * sx; diff --git a/src/Textures.cpp b/src/Textures.cpp index e5383429..eec82c40 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -504,16 +504,16 @@ void TextureCache::init() m_pMSDummy = addFrameBufferTexture(true); // we don't want to remove dummy texture _initDummyTexture(m_pMSDummy); - Context::InitTextureParams params; - params.handle = m_pMSDummy->name; - params.mipMapLevel = 0; - params.msaaLevel = config.video.multisampling; - params.width = m_pMSDummy->realWidth; - params.height = m_pMSDummy->realHeight; - params.format = colorFormat::RGBA; - params.internalFormat = gfxContext.convertInternalTextureFormat(u32(internalcolorFormat::RGBA8)); - params.dataType = datatype::UNSIGNED_BYTE; - gfxContext.init2DTexture(params); + Context::InitTextureParams msParams; + msParams.handle = m_pMSDummy->name; + msParams.mipMapLevel = 0; + msParams.msaaLevel = config.video.multisampling; + msParams.width = m_pMSDummy->realWidth; + msParams.height = m_pMSDummy->realHeight; + msParams.format = colorFormat::RGBA; + msParams.internalFormat = gfxContext.convertInternalTextureFormat(u32(internalcolorFormat::RGBA8)); + msParams.dataType = datatype::UNSIGNED_BYTE; + gfxContext.init2DTexture(msParams); activateMSDummy(0); activateMSDummy(1); @@ -763,7 +763,8 @@ void TextureCache::_loadBackground(CachedTexture *pTexture) if (_loadHiresBackground(pTexture)) return; - u32 *pDest; + u32 *pDest = nullptr; + u16 *pDest16 = nullptr; u8 *pSwapped, *pSrc; u32 numBytes, bpl; @@ -799,6 +800,7 @@ void TextureCache::_loadBackground(CachedTexture *pTexture) free(pSwapped); return; } + pDest16 = reinterpret_cast(pDest); clampSClamp = pTexture->width - 1; clampTClamp = pTexture->height - 1; @@ -813,9 +815,9 @@ void TextureCache::_loadBackground(CachedTexture *pTexture) tx = min(x, (u32)clampSClamp); if (glInternalFormat == internalcolorFormat::RGBA8) - ((u32*)pDest)[j++] = GetTexel((u64*)pSrc, tx, 0, pTexture->palette); + pDest[j++] = GetTexel((u64*)pSrc, tx, 0, pTexture->palette); else - ((u16*)pDest)[j++] = GetTexel((u64*)pSrc, tx, 0, pTexture->palette); + pDest16[j++] = static_cast(GetTexel((u64*)pSrc, tx, 0, pTexture->palette)); } } diff --git a/src/uCodes/T3DUX.cpp b/src/uCodes/T3DUX.cpp index 6759f311..d5a4382d 100644 --- a/src/uCodes/T3DUX.cpp +++ b/src/uCodes/T3DUX.cpp @@ -117,10 +117,13 @@ void T3DUX_LoadObject(u32 pstate, u32 pvtx, u32 ptri, u32 pcol) gSP.texture.scales = 1.0f; gSP.texture.scalet = 1.0f; - const u32 w0 = ostate->othermode0; - const u32 w1 = ostate->othermode1; - gDPSetOtherMode( _SHIFTR( w0, 0, 24 ), // mode0 - w1 ); // mode1 + { + const u32 w0 = ostate->othermode0; + const u32 w1 = ostate->othermode1; + gDPSetOtherMode( + _SHIFTR(w0, 0, 24), // mode0 + w1); // mode1 + } if ((ostate->matrixFlag & 1) == 0) //load matrix gSPForceMatrix(pstate + sizeof(T3DUXState)); diff --git a/src/uCodes/ZSortBOSS.cpp b/src/uCodes/ZSortBOSS.cpp index 32409b4d..c4f03aeb 100644 --- a/src/uCodes/ZSortBOSS.cpp +++ b/src/uCodes/ZSortBOSS.cpp @@ -479,6 +479,10 @@ void ZSortBOSS_TransposeMTX( u32, u32 _w1 ) case 0x8b0: mtx = (M44*)gSP.matrix.combined; break; + + default: + assert(false); + return; } memcpy(m, mtx, 64);