Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 193d5b2

Browse files
committed
Code cleanup from VC++ suggestions
1 parent e5c4345 commit 193d5b2

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

UIforETW/ChildProcess.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ DWORD ChildProcess::ListenerThread()
105105
bool lastWasCR = false;
106106
for (int in = 0, out = 0; /**/; /**/)
107107
{
108-
char c = buffer[in++];
108+
const char c = buffer[in++];
109109
// Edit controls on older versions of Windows (and by default on newer
110110
// versions) need \r\n line endings, \n is not sufficient.
111111
if (c == '\n' && !lastWasCR)
@@ -166,7 +166,7 @@ bool ChildProcess::Run(bool showCommand, string_type args)
166166
startupInfo.dwFlags = STARTF_USESTDHANDLES;
167167

168168
PROCESS_INFORMATION processInfo = {};
169-
const DWORD flags = CREATE_NO_WINDOW;
169+
constexpr DWORD flags = CREATE_NO_WINDOW;
170170
// Wacky CreateProcess rules say args has to be writable!
171171
std::vector<_TCHAR> argsCopy(args.size() + 1);
172172
_tcscpy_s(&argsCopy[0], argsCopy.size(), args.c_str());
@@ -186,15 +186,16 @@ bool ChildProcess::Run(bool showCommand, string_type args)
186186
return false;
187187
}
188188

189-
DWORD ChildProcess::GetExitCode()
189+
DWORD ChildProcess::GetExitCode() noexcept
190190
{
191191
if (!hProcess_)
192192
return 0;
193193
// Don't allow getting the exit code unless the process has exited.
194194
WaitForCompletion(true);
195195
DWORD result;
196-
(void)GetExitCodeProcess(hProcess_, &result);
197-
return result;
196+
if (GetExitCodeProcess(hProcess_, &result))
197+
return result;
198+
return 0;
198199
}
199200

200201
ChildProcess::string_type ChildProcess::GetOutput()

UIforETW/ChildProcess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ChildProcess
5353
// it will return zero. If the process is still running it
5454
// will wait until the process returns and then get the exit code.
5555
// This function will print output as it arrives with outputPrintf.
56-
DWORD GetExitCode();
56+
DWORD GetExitCode() noexcept;
5757

5858
// Normally all output is printed as it is received. If this function
5959
// is called after Run() then all output will be returned, and not

UIforETW/UIforETWDlg.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ limitations under the License.
3737
#define new DEBUG_NEW
3838
#endif
3939

40-
const int kRecordTraceHotKey = 1234;
41-
const int kTimerID = 5678;
40+
constexpr int kRecordTraceHotKey = 1234;
41+
constexpr int kTimerID = 5678;
4242

4343
// This static pointer to the main window is used by the global
4444
// outputPrintf function.
@@ -47,7 +47,7 @@ static CUIforETWDlg* pMainWindow;
4747
// This convenient hack function is so that the ChildProcess code can
4848
// print to the main output window. This function can only be called
4949
// from the main thread.
50-
void outputPrintf(_Printf_format_string_ const wchar_t* pFormat, ...)
50+
void outputPrintf(_Printf_format_string_ const wchar_t* pFormat, ...) noexcept
5151
{
5252
va_list args;
5353
va_start(args, pFormat);
@@ -324,7 +324,7 @@ void CUIforETWDlg::CheckSymbolDLLs()
324324

325325
// Previous versions of symsrv.dll may not be multithreading safe and therefore can't
326326
// be used with the latest WPA.
327-
const int64_t requiredSymsrvVersion = (10llu << 48) + 0 + (14321llu << 16) + (1024llu << 0);
327+
constexpr int64_t requiredSymsrvVersion = (10llu << 48) + 0 + (14321llu << 16) + (1024llu << 0);
328328
const auto symsrvVersion = GetFileVersion(symsrv_path);
329329
if (symsrvVersion < requiredSymsrvVersion)
330330
{
@@ -436,9 +436,9 @@ BOOL CUIforETWDlg::OnInitDialog()
436436
}
437437

438438
auto xperfVersion = GetFileVersion(GetXperfPath());
439-
const int64_t requiredXperfVersion = (10llu << 48) + 0 + (10586llu << 16) + (15llu << 0);
439+
constexpr int64_t requiredXperfVersion = (10llu << 48) + 0 + (10586llu << 16) + (15llu << 0);
440440
// Windows 10 spring 2019 version, 10.0.18362.1 - requires Windows 8 or higher?
441-
const int64_t preferredXperfVersion = (10llu << 48) + 0 + (18362llu << 16) + (1llu << 0);
441+
constexpr int64_t preferredXperfVersion = (10llu << 48) + 0 + (18362llu << 16) + (1llu << 0);
442442

443443
wchar_t systemDir[MAX_PATH];
444444
systemDir[0] = 0;
@@ -692,7 +692,7 @@ BOOL CUIforETWDlg::OnInitDialog()
692692
if (bVersionChecks_)
693693
versionCheckerThread_.StartVersionCheckerThread(this);
694694

695-
const UINT flags = SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;
695+
constexpr UINT flags = SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;
696696
// Resize our window per the previous dimensions if we have them
697697
SetWindowPos(nullptr, 0, 0, previousWidth_, previousHeight_, flags);
698698

@@ -1086,7 +1086,7 @@ void CUIforETWDlg::OnBnClickedStarttracing()
10861086
// This should also make the UI Delays and window-in-focus graphs more
10871087
// reliable, by not having them lose messages so frequently, although it is not
10881088
// clear that it actually helps.
1089-
const uint64_t kCritFlags = 0x0200000010000000;
1089+
constexpr uint64_t kCritFlags = 0x0200000010000000;
10901090
std::wstring userProviders = stringPrintf(L"Microsoft-Windows-Win32k:0x%llx", ~kCritFlags);
10911091
if (IsWindowsVistaOrLesser())
10921092
userProviders = L"Microsoft-Windows-LUA"; // Because Microsoft-Windows-Win32k doesn't work on Vista.
@@ -1765,7 +1765,7 @@ void CUIforETWDlg::OnSize(UINT nType, int /*cx*/, int /*cy*/)
17651765
lastHeight_ += yDelta;
17661766
previousHeight_ = lastHeight_;
17671767

1768-
const UINT flags = SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;
1768+
constexpr UINT flags = SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;
17691769

17701770
// Resize the output window, trace list, and notes control.
17711771

UIforETW/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// const float in a header file can lead to duplication of the storage
44
// but I don't really care in this case. Just don't do it with a header
55
// that is included hundreds of times.
6-
const float kCurrentVersion = 1.54f;
6+
constexpr float kCurrentVersion = 1.54f;
77

88
// Put a "#define VERSION_SUFFIX 'b'" line here to add a minor version
99
// increment that won't trigger the new-version checks, handy for minor

UIforETW/stdafx.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ limitations under the License.
5959
#include <VersionHelpers.h>
6060

6161
// Global function for printing to the dialog output window.
62-
void outputPrintf(_Printf_format_string_ const wchar_t* pFormat, ...);
62+
void outputPrintf(_Printf_format_string_ const wchar_t* pFormat, ...) noexcept;
6363
// Needed for int64_t and friends
6464
#include <inttypes.h>
6565

@@ -71,9 +71,9 @@ void CheckProcesses();
7171
#undef max
7272

7373
// Send this when the list of traces needs to be updated.
74-
const int WM_UPDATETRACELIST = WM_USER + 10;
74+
constexpr int WM_UPDATETRACELIST = WM_USER + 10;
7575
// Send this when a new version is detected.
76-
const int WM_NEWVERSIONAVAILABLE = WM_USER + 11;
76+
constexpr int WM_NEWVERSIONAVAILABLE = WM_USER + 11;
7777

7878
// Disable "warning C6054: String 'buffer' might not be zero-terminated." because
7979
// these warnings are spurious. They are caused by incorrect annotations on

include/ETWProviders/etwprof.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef long long int64;
4141

4242
// Flag to indicate that a mouse-down actually corresponds to a double-click.
4343
// Add this to the button number.
44-
const int kFlagDoubleClick = 100;
44+
constexpr int kFlagDoubleClick = 100;
4545

4646
#ifdef ETW_MARKS_ENABLED
4747

0 commit comments

Comments
 (0)