From f7d0af8d88c9e13a5a5da6d4d54f76581c7e51c4 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sun, 19 Feb 2023 16:27:24 +0900 Subject: [PATCH] Fix Code scanning alert: Unused local variable --- Src/Common/RegOptionsMgr.cpp | 2 +- Src/ConflictFileParser.cpp | 8 ++++++++ Src/DirDoc.cpp | 3 +-- Src/MainFrm.cpp | 5 ++--- Src/MergeDoc.cpp | 7 +++---- Src/MergeEditView.cpp | 5 ++--- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Src/Common/RegOptionsMgr.cpp b/Src/Common/RegOptionsMgr.cpp index 9ca8d84d3..3df9d2f0c 100644 --- a/Src/Common/RegOptionsMgr.cpp +++ b/Src/Common/RegOptionsMgr.cpp @@ -186,7 +186,7 @@ int CRegOptionsMgr::LoadValueFromReg(HKEY hKey, const String& strName, DWORD type = 0; DWORD size = 0; int retVal = COption::OPT_OK; - auto [strPath, strValueName] = SplitName(strName); + [[maybe_unused]] auto [strPath, strValueName] = SplitName(strName); // Get type and size of value in registry retValReg = RegQueryValueEx(hKey, strValueName.c_str(), 0, &type, diff --git a/Src/ConflictFileParser.cpp b/Src/ConflictFileParser.cpp index 5c53d602e..f5fb82e4f 100644 --- a/Src/ConflictFileParser.cpp +++ b/Src/ConflictFileParser.cpp @@ -98,11 +98,19 @@ bool ParseConflictFile(const String& conflictFileName, // open input file bool success = conflictFile.OpenReadOnly(conflictFileName); + if (!success) + return false; // Create output files bool success2 = workingCopy.Open(workingCopyFileName, _T("wb")); + if (!success2) + return false; bool success3 = newRevision.Open(newRevisionFileName, _T("wb")); + if (!success3) + return false; bool success4 = baseRevision.Open(baseRevisionFileName, _T("wb")); + if (!success4) + return false; // detect codepage of conflict file FileTextEncoding encoding = codepage_detect::Guess(conflictFileName, iGuessEncodingType); diff --git a/Src/DirDoc.cpp b/Src/DirDoc.cpp index f9d06d2be..44bf01637 100644 --- a/Src/DirDoc.cpp +++ b/Src/DirDoc.cpp @@ -488,8 +488,7 @@ void CDirDoc::SetDirView(CDirView * newView) m_pDirView = newView; // MFC has a view list for us, so lets check against it POSITION pos = GetFirstViewPosition(); - CDirView * temp = static_cast(GetNextView(pos)); - ASSERT(temp == m_pDirView); // verify that our stashed pointer is the same as MFC's + ASSERT(m_pDirView == static_cast(GetNextView(pos))); // verify that our stashed pointer is the same as MFC's } /** diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index 076f29b6d..87eb0c1cb 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -2525,8 +2525,7 @@ static void LoadHiColImageList(UINT nIDResource, int nWidth, int nHeight, int nN bm.Attach(LoadBitmapAndConvertTo32bit(AfxGetInstanceHandle(), nIDResource, nNewWidth * nCount, nNewHeight, bGrayscale, RGB(0xff, 0, 0xff))); VERIFY(ImgList.Create(nNewWidth, nNewHeight, ILC_COLOR32, nCount, 0)); - int nIndex = ImgList.Add(&bm, nullptr); - ASSERT(-1 != nIndex); + ASSERT(-1 != ImgList.Add(&bm, nullptr)); } /** @@ -3343,7 +3342,7 @@ String CMainFrame::GetPluginPipelineByMenuId(unsigned idSearch, const std::vecto { PluginInfo* pluginFound = nullptr; String pluginName; - auto [suggestedPlugins, allPlugins] = FileTransform::CreatePluginMenuInfos(_T(""), events, baseId); + [[maybe_unused]] auto [suggestedPlugins, allPlugins] = FileTransform::CreatePluginMenuInfos(_T(""), events, baseId); for (const auto& [processType, pluginList] : allPlugins) { for (const auto& [caption, name, id, plugin] : pluginList) diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index 3bc6318bc..3c4b311c3 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -63,7 +63,7 @@ using std::swap; int CMergeDoc::m_nBuffersTemp = 2; -static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, int nStartLine = 0, int nLines = -1); +static int SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, int nStartLine = 0, int nLines = -1); ///////////////////////////////////////////////////////////////////////////// // CMergeDoc @@ -290,14 +290,14 @@ void CMergeDoc::Serialize(CArchive& ar) * (the plugins are optional, not the conversion) * @todo Show SaveToFile() errors? */ -static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, int nStartLine, int nLines) +static int SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, int nStartLine, int nLines) { // and we don't repack the file PackingInfo tempPacker(false); // write buffer out to temporary file String sError; - int retVal = buf.SaveToFile(filepath, true, sError, tempPacker, + return buf.SaveToFile(filepath, true, sError, tempPacker, CRLFSTYLE::AUTOMATIC, false, nStartLine, nLines); } @@ -3878,7 +3878,6 @@ void CMergeDoc::OnFileRecompareAs(UINT nID) DWORD dwFlags[3] = { 0 }; PathContext paths = m_filePaths; String strDesc[3]; - int nBuffers = m_nBuffers; PackingInfo infoUnpacker(m_infoUnpacker.GetPluginPipeline()); for (int pane = 0; pane < m_nBuffers; pane++) diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index 18a0b180c..b060ac25a 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -2179,7 +2179,7 @@ void CMergeEditView::OnAllLeft() void CMergeEditView::OnUpdateAllLeft(CCmdUI* pCmdUI) { // Check that left side is not readonly - auto [srcPane, dstPane] = CMergeFrameCommon::MenuIDtoXY(pCmdUI->m_nID, m_nThisPane, GetDocument()->m_nBuffers); + [[maybe_unused]] auto [srcPane, dstPane] = CMergeFrameCommon::MenuIDtoXY(pCmdUI->m_nID, m_nThisPane, GetDocument()->m_nBuffers); if (!IsReadOnly(dstPane)) pCmdUI->Enable(GetDocument()->m_diffList.HasSignificantDiffs()); else @@ -2209,7 +2209,7 @@ void CMergeEditView::OnAllRight() void CMergeEditView::OnUpdateAllRight(CCmdUI* pCmdUI) { // Check that right side is not readonly - auto [srcPane, dstPane] = CMergeFrameCommon::MenuIDtoXY(pCmdUI->m_nID, m_nThisPane, GetDocument()->m_nBuffers); + [[maybe_unused]] auto [srcPane, dstPane] = CMergeFrameCommon::MenuIDtoXY(pCmdUI->m_nID, m_nThisPane, GetDocument()->m_nBuffers); if (!IsReadOnly(dstPane)) pCmdUI->Enable(GetDocument()->m_diffList.HasSignificantDiffs()); else @@ -4318,7 +4318,6 @@ void CMergeEditView::OnWindowSplit() auto& wndSplitter = dynamic_cast(GetParentFrame())->GetSplitter(); CMergeDoc *pDoc = GetDocument(); - CMergeEditView *pView = pDoc->GetView(0, m_nThisPane); int nBuffer = m_nThisPane; if (pDoc->m_nGroups <= 2) { -- 2.11.0