From 40b814bc37892c8fa603f9c6c856f9b8ac673ece Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 14 Jun 2019 08:08:26 +0900 Subject: [PATCH] Avoid using memset() for structure initialization --- Externals/crystaledit/editlib/ccrystaltextview.cpp | 2 +- Src/Common/BCMenu.h | 4 +--- Src/ConfigLog.cpp | 4 +--- Src/DiffFileData.cpp | 2 +- Src/DiffList.h | 12 +++++------- Src/DiffWrapper.h | 10 +++++----- Src/HexMergeDoc.cpp | 6 +++--- Src/ImgMergeFrm.cpp | 4 ++-- Src/MergeStatusBar.cpp | 4 +--- Src/MovedBlocks.cpp | 8 ++++---- 10 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index a63b047c9..c1aa90423 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -4451,7 +4451,7 @@ GetResourceHandle () int CCrystalTextView:: OnCreate (LPCREATESTRUCT lpCreateStruct) { - memset (&m_lfBaseFont, 0, sizeof (m_lfBaseFont)); + m_lfBaseFont = {}; _tcscpy_s (m_lfBaseFont.lfFaceName, _T ("FixedSys")); m_lfBaseFont.lfHeight = 0; m_lfBaseFont.lfWeight = FW_NORMAL; diff --git a/Src/Common/BCMenu.h b/Src/Common/BCMenu.h index 30aaf8e2a..9f96aee3e 100644 --- a/Src/Common/BCMenu.h +++ b/Src/Common/BCMenu.h @@ -53,10 +53,8 @@ public: struct CMenuItemInfo : public MENUITEMINFO { - CMenuItemInfo() + CMenuItemInfo() : MENUITEMINFO{ sizeof(MENUITEMINFO) } { - memset(this, 0, sizeof(MENUITEMINFO)); - cbSize = sizeof(MENUITEMINFO); } }; diff --git a/Src/ConfigLog.cpp b/Src/ConfigLog.cpp index df85a3e9d..8ec87d5b3 100644 --- a/Src/ConfigLog.cpp +++ b/Src/ConfigLog.cpp @@ -461,9 +461,7 @@ String CConfigLog::GetProcessorInfo() const SYSTEM_INFO siSysInfo; ::GetSystemInfo(&siSysInfo); - MEMORYSTATUSEX GlobalMemoryBuffer; - memset(&GlobalMemoryBuffer, 0, sizeof(GlobalMemoryBuffer)); - GlobalMemoryBuffer.dwLength = sizeof (GlobalMemoryBuffer); + MEMORYSTATUSEX GlobalMemoryBuffer = {sizeof (GlobalMemoryBuffer)}; ::GlobalMemoryStatusEx(&GlobalMemoryBuffer); ULONG lInstalledMemory = (ULONG)(GlobalMemoryBuffer.ullTotalPhys / (1024*1024)); diff --git a/Src/DiffFileData.cpp b/Src/DiffFileData.cpp index d700ef6b0..6af31e832 100644 --- a/Src/DiffFileData.cpp +++ b/Src/DiffFileData.cpp @@ -124,7 +124,7 @@ void DiffFileData::Reset() _close(m_inf[i].desc); } m_inf[i].desc = 0; - memset(&m_inf[i], 0, sizeof(m_inf[i])); + m_inf[i] = {}; } } diff --git a/Src/DiffList.h b/Src/DiffList.h index 913a63bc3..bbe58d649 100644 --- a/Src/DiffList.h +++ b/Src/DiffList.h @@ -62,16 +62,14 @@ enum */ struct DIFFRANGE { - int begin[3]; /**< First diff line in original file1,2,3 */ - int end[3]; /**< Last diff line in original file1,2,3 */ - int dbegin; /**< Synchronised (ghost lines added) first diff line in file1,2,3 */ - int dend; /**< Synchronised (ghost lines added) last diff line in file1,2,3 */ - int blank[3]; /**< Number of blank lines in file1,2,3 */ + int begin[3] = {}; /**< First diff line in original file1,2,3 */ + int end[3] = {}; /**< Last diff line in original file1,2,3 */ + int dbegin = 0; /**< Synchronised (ghost lines added) first diff line in file1,2,3 */ + int dend = 0; /**< Synchronised (ghost lines added) last diff line in file1,2,3 */ + int blank[3] = {-1, -1, -1}; /**< Number of blank lines in file1,2,3 */ OP_TYPE op; /**< Operation done with this diff */ DIFFRANGE() { - memset(this, 0, sizeof(*this)); - blank[0] = blank[1] = blank[2] = -1; } void swap_sides(int index1, int index2); }; diff --git a/Src/DiffWrapper.h b/Src/DiffWrapper.h index 2dc2d49e8..bc0b8bc1a 100644 --- a/Src/DiffWrapper.h +++ b/Src/DiffWrapper.h @@ -129,12 +129,12 @@ typedef enum { */ struct DIFFSTATUS { - bool bMissingNL[3]; /**< file is missing EOL before EOF */ - bool bBinaries; /**< Files are binaries */ - IDENTLEVEL Identical; /**< diffutils said files are identical */ - bool bPatchFileFailed; /**< Creating patch file failed */ + bool bMissingNL[3] {}; /**< file is missing EOL before EOF */ + bool bBinaries = false; /**< Files are binaries */ + IDENTLEVEL Identical = IDENTLEVEL_NONE; /**< diffutils said files are identical */ + bool bPatchFileFailed = false; /**< Creating patch file failed */ - DIFFSTATUS() { memset(this, 0, sizeof(*this)); } // start out with all flags clear + DIFFSTATUS() {} void MergeStatus(const DIFFSTATUS& other) { if (Identical == IDENTLEVEL_ALL) diff --git a/Src/HexMergeDoc.cpp b/Src/HexMergeDoc.cpp index dfb9d758f..17db52ad1 100644 --- a/Src/HexMergeDoc.cpp +++ b/Src/HexMergeDoc.cpp @@ -125,11 +125,11 @@ END_MESSAGE_MAP() */ CHexMergeDoc::CHexMergeDoc() : m_pDirDoc(nullptr) +, m_nBuffers(m_nBuffersTemp) +, m_pView{} +, m_nBufferType{BUFFER_NORMAL, BUFFER_NORMAL, BUFFER_NORMAL} { - m_nBuffers = m_nBuffersTemp; m_filePaths.SetSize(m_nBuffers); - std::fill_n(m_pView, m_nBuffers, static_cast(nullptr)); - std::fill_n(m_nBufferType, m_nBuffers, BUFFER_NORMAL); } /** diff --git a/Src/ImgMergeFrm.cpp b/Src/ImgMergeFrm.cpp index 770399af8..ae144f1df 100644 --- a/Src/ImgMergeFrm.cpp +++ b/Src/ImgMergeFrm.cpp @@ -162,9 +162,9 @@ CImgMergeFrame::CImgMergeFrame() , m_bAutoMerged(false) , m_pImgMergeWindow(nullptr) , m_pImgToolWindow(nullptr) +, m_nBufferType{BUFFER_NORMAL, BUFFER_NORMAL, BUFFER_NORMAL} +, m_bRO{} { - std::fill_n(m_nBufferType, 3, BUFFER_NORMAL); - std::fill_n(m_bRO, 3, false); } CImgMergeFrame::~CImgMergeFrame() diff --git a/Src/MergeStatusBar.cpp b/Src/MergeStatusBar.cpp index 7592b3e1e..c6f37edb9 100644 --- a/Src/MergeStatusBar.cpp +++ b/Src/MergeStatusBar.cpp @@ -86,15 +86,13 @@ END_MESSAGE_MAP() /** * @brief Constructor. */ -CMergeStatusBar::CMergeStatusBar() : m_nPanes(2) +CMergeStatusBar::CMergeStatusBar() : m_nPanes(2), m_bDiff{}, m_dispFlags{} { for (int pane = 0; pane < sizeof(m_status) / sizeof(m_status[0]); pane++) { m_status[pane].m_pWndStatusBar = this; m_status[pane].m_base = PANE_PANE0_INFO + pane * nColumnsPerPane; } - std::fill_n(m_bDiff, sizeof(m_bDiff)/sizeof(m_bDiff[0]), false); - std::fill_n(m_dispFlags, sizeof(m_dispFlags)/sizeof(m_dispFlags[0]), 0); Options::DiffColors::Load(GetOptionsMgr(), m_cachedColors); } diff --git a/Src/MovedBlocks.cpp b/Src/MovedBlocks.cpp index 755890a69..4e0267422 100644 --- a/Src/MovedBlocks.cpp +++ b/Src/MovedBlocks.cpp @@ -187,7 +187,7 @@ extern "C" void moved_block_analysis(struct change ** pscript, struct file_data // so no right side on newob // newob will be the moved part only, later after we split off any suffix from it struct change *newob = (struct change *) xmalloc (sizeof (struct change)); - memset(newob, 0, sizeof(*newob)); + *newob = {}; newob->line0 = i1; newob->line1 = e->line1 + e->inserted; @@ -213,7 +213,7 @@ extern "C" void moved_block_analysis(struct change ** pscript, struct file_data // break off any suffix from e // newob will be the suffix, and will get all the right side struct change *newob = (struct change *) xmalloc (sizeof (struct change)); - memset(newob, 0, sizeof(*newob)); + *newob = {}; newob->line0 = i2+1; newob->line1 = e->line1; @@ -305,7 +305,7 @@ extern "C" void moved_block_analysis(struct change ** pscript, struct file_data // so no right side on newob // newob will be the moved part only, later after we split off any suffix from it struct change *newob = (struct change *) xmalloc (sizeof (struct change)); - memset(newob, 0, sizeof(*newob)); + *newob = {}; newob->line0 = e->line0 + e->deleted; newob->line1 = j1; @@ -331,7 +331,7 @@ extern "C" void moved_block_analysis(struct change ** pscript, struct file_data // break off any suffix from e // newob will be the suffix, and will get all the left side struct change *newob = (struct change *) xmalloc (sizeof (struct change)); - memset(newob, 0, sizeof(*newob)); + *newob = {}; newob->line0 = e->line0; newob->line1 = j2+1; -- 2.11.0