Skip to content

Commit

Permalink
Additional low-level cleanups (2)
Browse files Browse the repository at this point in the history
* More `while (1)` becomes `while (true)`
* More use of `ptr != nullptr` in conditionals
* Also `handle!=nullptr`in conditionals
* Also `while (ptr)` becomes `while (ptr != nullptr)`
* Add `{ ... }` brackets to a `do ... while()`
* Some `while(int)` changed to `while (int!=0)`
  • Loading branch information
GreyMerlin authored and sdottaka committed Jan 5, 2019
1 parent da5c3db commit ae6ae09
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Externals/crystaledit/editlib/ccrystaleditview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2734,14 +2734,14 @@ int (*CCrystalEditView::SpellConfig) (SpellData*);

bool CCrystalEditView::LoadSpellDll (bool bAlert /*= true*/)
{
if (hSpellDll)
if (hSpellDll != nullptr)
return true;
CString sPath = szWIspellPath;
if (!sPath.IsEmpty () && sPath[sPath.GetLength () - 1] != _T('\\'))
sPath += _T ('\\');
sPath += _T ("wispell.dll");
hSpellDll = LoadLibrary (sPath);
if (hSpellDll)
if (hSpellDll != nullptr)
{
SpellInit = (int (*) (SpellData*)) GetProcAddress (hSpellDll, "SpellInit");
SpellCheck = (int (*) (SpellData*)) GetProcAddress (hSpellDll, "SpellCheck");
Expand Down
2 changes: 2 additions & 0 deletions Externals/crystaledit/editlib/filesup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ int GetNamePosition (LPCTSTR pszString)
int posit = sString.GetLength ();
TCHAR test;
do
{
#ifdef _UNICODE
if ((test = sString.GetAt (--posit)) == _T ('\\') || test == _T (':'))
#else
if (((test = sString.GetAt (--posit)) == _T ('\\') && !_ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) || test == _T (':'))
#endif
return posit + 1;
}
while (posit);
return posit;
}
Expand Down
2 changes: 1 addition & 1 deletion Externals/crystaledit/editlib/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ bool
RegSaveString (HKEY hKey, LPCTSTR pszSubKey, LPCTSTR pszValName, LPCTSTR pszString)
{
HKEY hSubKey = pszSubKey ? RegCreate (hKey, pszSubKey, KEY_WRITE) : hKey;
if (hSubKey)
if (hSubKey != nullptr)
{
if (RegSetValueEx (hSubKey, pszValName, 0, REG_SZ, (LPBYTE) pszString, (DWORD)(_tcslen (pszString) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS)
{
Expand Down
14 changes: 7 additions & 7 deletions Src/Common/CMoveConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ bool
CMoveConstraint::
ConstrainItem(int nId, double fLeftX, double fExpandX, double fAboveY, double fExpandY)
{
if (!m_hwndDlg || !IsWindow(m_hwndDlg))
if (m_hwndDlg == nullptr || !IsWindow(m_hwndDlg))
return false;
HWND hwnd = GetDlgItem(m_hwndDlg, nId);
return DoConstrain(0, hwnd, fLeftX, fExpandX, fAboveY, fExpandY);
Expand Down Expand Up @@ -377,7 +377,7 @@ CMoveConstraint::UnSubclassWnd()
void
CMoveConstraint::CheckDeferredChildren()
{
if (!m_nDelayed)
if (m_nDelayed == 0)
return;
ConstraintList & constraintList = m_ConstraintList;
for (POSITION pos=constraintList.GetHeadPosition(); pos != nullptr; constraintList.GetNext(pos))
Expand Down Expand Up @@ -408,15 +408,15 @@ CMoveConstraint::Resize(HWND hWnd, UINT nType)

if (nType == SIZE_MINIMIZED) return;

if (!m_hwndDlg && hWnd != nullptr && !m_bOriginalFetched)
if (m_hwndDlg == nullptr && hWnd != nullptr && !m_bOriginalFetched)
{
// if early subclass or wndproc
// grab early dimensions, in case we want them later (eg, property sheet)
GrabCurrentDimensionsAsOriginal(hWnd);
return;
}

if (!m_hwndDlg || !IsWindow(m_hwndDlg))
if (m_hwndDlg == nullptr || !IsWindow(m_hwndDlg))
return;

CRect rectParentCurrent;
Expand Down Expand Up @@ -478,7 +478,7 @@ void
CMoveConstraint::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// views don't get WM_GETMINMAXINFO, but dialogs & frames do
if (!m_hwndDlg)
if (m_hwndDlg == nullptr)
return;
if (m_nMinX)
lpMMI->ptMinTrackSize.x = m_nMinX;
Expand All @@ -494,7 +494,7 @@ bool
CMoveConstraint::PaintGrip()
{
if (m_nGrip == SG_NONE) return false;
if (!m_hwndDlg) return false;
if (m_hwndDlg == nullptr) return false;
HWND hw = (m_nGrip == SG_PARENTSTATE) ? GetParent(m_hwndDlg) : m_hwndDlg;
return !IsZoomed(hw) && !IsIconic(hw);
}
Expand All @@ -507,7 +507,7 @@ bool
CMoveConstraint::OnNcHitTest(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT * plresult)
{
// views don't get WM_NCHITTEST, but dialogs & frames do
if (!m_hwndDlg)
if (m_hwndDlg == nullptr)
return false;
if (m_nMinY == m_nMaxY)
{
Expand Down
6 changes: 3 additions & 3 deletions Src/Common/ClipBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void PutFilesToClipboard(const Container& list, HWND currentWindowHandle)

// CF_HDROP
HGLOBAL hDrop = GlobalAlloc(GHND, sizeof(DROPFILES) + sizeof(TCHAR) * strPaths.length());
if (!hDrop)
if (hDrop == nullptr)
return;
if (TCHAR *pDrop = static_cast<TCHAR *>(GlobalLock(hDrop)))
{
Expand All @@ -51,7 +51,7 @@ void PutFilesToClipboard(const Container& list, HWND currentWindowHandle)

// CF_DROPEFFECT
HGLOBAL hDropEffect = GlobalAlloc(GHND, sizeof(DWORD));
if (!hDropEffect)
if (hDropEffect == nullptr)
{
GlobalFree(hDrop);
return;
Expand All @@ -64,7 +64,7 @@ void PutFilesToClipboard(const Container& list, HWND currentWindowHandle)

// CF_UNICODETEXT
HGLOBAL hPathnames = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, sizeof(TCHAR) * (strPathsSepSpc.length() + 1));
if (!hPathnames)
if (hPathnames == nullptr)
{
GlobalFree(hDrop);
GlobalFree(hDropEffect);
Expand Down
6 changes: 3 additions & 3 deletions Src/Common/LanguageSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ LangFileInfo::LangFileInfo(LPCTSTR path)
if (_tfopen_s(&f, path, _T("r")) == 0 && f)
{
char buf[1024 + 1];
while (fgets(buf, sizeof buf - 1, f))
while (fgets(buf, sizeof buf - 1, f) != nullptr)
{
int i = 0;
strcat_s(buf, "1");
sscanf_s(buf, "msgid \" LANG_ENGLISH , SUBLANG_ENGLISH_US \" %d", &i);
if (i)
{
if (fgets(buf, sizeof buf, f))
if (fgets(buf, sizeof buf, f) != nullptr)
{
char *lang = strstr(buf, "LANG_");
char *sublang = strstr(buf, "SUBLANG_");
Expand Down Expand Up @@ -685,7 +685,7 @@ bool CLanguageSelect::LoadLanguageFile(LANGID wLangId, bool bShowError /*= false
std::string format;
std::string msgstr;
std::string directive;
while (fgets(buf, sizeof buf, f))
while (fgets(buf, sizeof buf, f) != nullptr)
{
if (char *p0 = EatPrefix(buf, "#:"))
{
Expand Down
4 changes: 2 additions & 2 deletions Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ void CMDITabBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
if (::IsWindow(hwndFrame))
{
HICON hIcon = (HICON)::SendMessage(hwndFrame, WM_GETICON, ICON_SMALL2, 0);
if (!hIcon)
if (hIcon == nullptr)
hIcon = (HICON)GetClassLongPtr(hwndFrame, GCLP_HICONSM);
if (hIcon)
if (hIcon != nullptr)
DrawIconEx(lpDraw->hDC, rc.left - iconsize.cx - 2, rc.top + (rc.bottom - rc.top - iconsize.cy) / 2, hIcon, iconsize.cx, iconsize.cy, 0, nullptr, DI_NORMAL);
}
DrawText(lpDraw->hDC, szBuf, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
Expand Down
4 changes: 2 additions & 2 deletions Src/Common/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ bool CPicture::Load(UINT nIDRes)
HRSRC hRsrc = ::FindResource(hInst,
MAKEINTRESOURCE(nIDRes),
TEXT("IMAGE")); // type
if (!hRsrc)
if (hRsrc == nullptr)
return false;

// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
if (lpRsrc == nullptr)
return false;

// create memory file and load it
Expand Down
2 changes: 1 addition & 1 deletion Src/Common/UnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ String trim_ws_end(const String & str)

String format_arg_list(const TCHAR *fmt, va_list args)
{
if (!fmt)
if (fmt == nullptr)
return _T("");
int result = -1;
int length = 256;
Expand Down
2 changes: 1 addition & 1 deletion Src/Common/unicoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void buffer::resize(size_t newSize)
{
capacity = newSize;
unsigned char *tmp = static_cast<unsigned char *>(realloc(ptr, capacity));
if (!tmp)
if (tmp == nullptr)
throw std::bad_alloc();
ptr = tmp;
}
Expand Down
4 changes: 2 additions & 2 deletions Src/CompareEngines/Wrap_DiffUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int DiffUtils::diffutils_compare_files()
/* Determine range of line numbers involved in each file. */
int first0 = 0, last0 = 0, first1 = 0, last1 = 0, deletes = 0, inserts = 0;
analyze_hunk (thisob, &first0, &last0, &first1, &last1, &deletes, &inserts, m_inf);
if (deletes || inserts || thisob->trivial)
if (deletes!=0 || inserts!=0 || thisob->trivial!=0)
{
/* Print the lines that the first file has. */
int trans_a0 = 0, trans_b0 = 0, trans_a1 = 0, trans_b1 = 0;
Expand All @@ -166,7 +166,7 @@ int DiffUtils::diffutils_compare_files()
if(m_pOptions->m_filterCommentsLines)
{
OP_TYPE op = OP_NONE;
if (!deletes && !inserts)
if (deletes == 0 && inserts == 0)
op = OP_TRIVIAL;
else
op = OP_DIFF;
Expand Down
4 changes: 2 additions & 2 deletions Src/DiffTextBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void EscapeControlChars(String &s)
size_t n = s.length();
LPCTSTR q = s.c_str();
size_t i = n;
while (i)
while (i != 0)
{
TCHAR c = q[--i];
// Is it a control character in the range 0..31 except TAB?
Expand All @@ -78,7 +78,7 @@ static void EscapeControlChars(String &s)
s.resize(n + 1);
LPTSTR p = &s[0];
// Copy/translate characters starting at end of string
while (i)
while (i != 0)
{
TCHAR c = p[--i];
// Is it a control character in the range 0..31 except TAB?
Expand Down
2 changes: 1 addition & 1 deletion Src/DirActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ bool GetOpenThreeItems(const CDiffContext& ctxt, uintptr_t pos1, uintptr_t pos2,
// FIXME:
for (int nIndex = 0; nIndex < 3; ++nIndex)
nPane[nIndex] = nIndex;
if (!pos3)
if (pos3 == 0)
{
// Two items selected, get their info
pdi[0] = &ctxt.GetDiffAt(pos1);
Expand Down
2 changes: 1 addition & 1 deletion Src/DirCmpReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static HGLOBAL ConvertToUTF16ForClipboard(HGLOBAL hMem, int codepage)
{
size_t len = GlobalSize(hMem);
HGLOBAL hMemW = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT, (len + 1) * sizeof(wchar_t));
if (!hMemW)
if (hMemW == nullptr)
return nullptr;
LPCSTR pstr = reinterpret_cast<LPCSTR>(GlobalLock(hMem));
LPWSTR pwstr = reinterpret_cast<LPWSTR>(GlobalLock(hMemW));
Expand Down
12 changes: 6 additions & 6 deletions Src/DirScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DiffWorker: public Runnable
CAssureScriptsForThread scriptsForRescan;

AutoPtr<Notification> pNf(m_queue.waitDequeueNotification());
while (pNf)
while (pNf.get() != nullptr)
{
WorkNotification* pWorkNf = dynamic_cast<WorkNotification*>(pNf.get());
if (pWorkNf) {
Expand Down Expand Up @@ -491,11 +491,11 @@ static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uint
CDiffContext *pCtxt = myStruct->context;
int res = 0;
int count = 0;
if (!parentdiffpos)
if (parentdiffpos == 0)
myStruct->pSemaphore->wait();
stopwatch.start();
uintptr_t pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
while (pos)
while (pos != 0)
{
if (pCtxt->ShouldAbort())
break;
Expand Down Expand Up @@ -538,10 +538,10 @@ static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uint
while (count > 0)
{
AutoPtr<Notification> pNf(queueResult.waitDequeueNotification());
if (!pNf)
if (pNf.get() == nullptr)
break;
WorkCompletedNotification* pWorkCompletedNf = dynamic_cast<WorkCompletedNotification*>(pNf.get());
if (pWorkCompletedNf) {
if (pWorkCompletedNf != nullptr) {
DIFFITEM &di = pWorkCompletedNf->data();
if (di.diffcode.isResultDiff() ||
(!di.diffcode.existAll() && !di.diffcode.isResultFiltered()))
Expand Down Expand Up @@ -765,7 +765,7 @@ void CompareDiffItem(DIFFITEM &di, CDiffContext * pCtxt)
static void StoreDiffData(DIFFITEM &di, CDiffContext * pCtxt,
const FolderCmp * pCmpData)
{
if (pCmpData)
if (pCmpData != nullptr)
{
di.nsdiffs = pCmpData->m_ndiffs;
di.nidiffs = pCmpData->m_ntrivialdiffs;
Expand Down
2 changes: 1 addition & 1 deletion Src/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ String GetTemporaryFileName(const String& lpPathName, const String& lpPrefixStri
if (lpPathName.length() > MAX_PATH-14)
return _T(""); // failure
int rtn = ::GetTempFileName(lpPathName.c_str(), lpPrefixString.c_str(), 0, buffer);
if (!rtn)
if (rtn == 0)
{
int err = GetLastError();
if (pnerr != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion Src/FilterCommentsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void FilterCommentsManager::Load()
catch (...)
{
}
if (!SectionNo)
if (SectionNo == 0)
{//If no markers were found, then initialize default markers
CreateDefaultMarkers();
}
Expand Down
2 changes: 1 addition & 1 deletion Src/LineFiltersList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void LineFiltersList::Import(const String& filters)
{
// find each regular expression and add to list
TCHAR *token = _tcstok_s(p_filters, sep, &pfilterNext);
while (token)
while (token != nullptr)
{
AddFilter(token, true);
token = _tcstok_s(nullptr, sep, &pfilterNext);
Expand Down
2 changes: 1 addition & 1 deletion Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ bool CMainFrame::ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocati
if (m_pMenus[MENU_HEXMERGEVIEW] == nullptr)
theApp.m_pHexMergeTemplate->m_hMenuShared = NewHexMergeViewMenu();
CHexMergeDoc *pHexMergeDoc = GetMergeDocForDiff<CHexMergeDoc>(theApp.m_pHexMergeTemplate, pDirDoc, nFiles);
if (!pHexMergeDoc)
if (pHexMergeDoc == nullptr)
return false;

if (!pHexMergeDoc->OpenDocs(nFiles, fileloc, GetROFromFlags(nFiles, dwFlags).data(), strDesc, GetActivePaneFromFlags(nFiles, dwFlags)))
Expand Down
2 changes: 1 addition & 1 deletion Src/MergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ int CMergeDoc::LoadFile(CString sFileName, int nBuffer, bool & readOnly, const F
*/
bool CMergeDoc::IsValidCodepageForMergeEditor(unsigned cp) const
{
if (!cp) // 0 is our signal value for invalid
if (cp == 0) // 0 is our signal value for invalid
return false;
return GetEncodingNameFromCodePage(cp) != nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions Src/TempFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ void CleanupWMtemp()
pEntry.dwSize = sizeof(pEntry);

// Get first process
bool hRes = !!Process32First (hSnapShot, &pEntry);
bool bRes = !!Process32First (hSnapShot, &pEntry);

// Iterate through all processes to get
// the ProcessIDs of all running WM instances
while (hRes)
while (bRes)
{
size_t exeFileLen = _tcslen(pEntry.szExeFile);
if ((exeFileLen >= sizeof(ExecutableFilenameU)/sizeof(TCHAR)-1 && _tcsicmp(pEntry.szExeFile + exeFileLen - (sizeof(ExecutableFilenameU)/sizeof(TCHAR)-1), ExecutableFilenameU) == 0) ||
(exeFileLen >= sizeof(ExecutableFilename )/sizeof(TCHAR)-1 && _tcsicmp(pEntry.szExeFile + exeFileLen - (sizeof(ExecutableFilename )/sizeof(TCHAR)-1), ExecutableFilename ) == 0))
{
processIDs.push_back(pEntry.th32ProcessID);
}
hRes = !!Process32Next (hSnapShot, &pEntry);
bRes = !!Process32Next (hSnapShot, &pEntry);
}

// Now remove temp folders that are not used.
Expand Down
Loading

0 comments on commit ae6ae09

Please sign in to comment.