Skip to content

Commit e1091b4

Browse files
Address some static-analysis warnings
1 parent 9263c70 commit e1091b4

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

PresentMon/LateStageReprojectionData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void UpdateConsole(std::unordered_map<uint32_t, ProcessInfo> const& activeProces
330330
ConsolePrint(" %.2lf ms/frame (%.1lf fps", 1000.0 / fps, fps);
331331
}
332332

333-
ConsolePrintLn(", %.1lf%% of Compositor frame rate)", double(historySize - runtimeStats.mAppMissedFrames) / (historySize) * 100.0f);
333+
ConsolePrintLn(", %.1lf%% of Compositor frame rate)", historySize == 0 ? 0.0 : double(historySize - runtimeStats.mAppMissedFrames) / (historySize) * 100.0);
334334

335335
ConsolePrintLn(" Missed Present: %Iu total in last %.1lf seconds (%Iu total observed)",
336336
runtimeStats.mAppMissedFrames,

PresentMon/OutputThread.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,21 @@ void SetOutputRecordingState(bool record)
3232
{
3333
auto const& args = GetCommandLineArgs();
3434

35-
if (gIsRecording == record) {
36-
return;
37-
}
35+
EnterCriticalSection(&gRecordingToggleCS);
3836

39-
// When capturing from an ETL file, just use the current recording state.
40-
// It's not clear how best to map realtime to ETL QPC time, and there
41-
// aren't any realtime cues in this case.
42-
if (args.mEtlFileName != nullptr) {
43-
EnterCriticalSection(&gRecordingToggleCS);
37+
if (gIsRecording != record) {
4438
gIsRecording = record;
45-
LeaveCriticalSection(&gRecordingToggleCS);
46-
return;
47-
}
4839

49-
uint64_t qpc = 0;
50-
QueryPerformanceCounter((LARGE_INTEGER*) &qpc);
40+
// When capturing from an ETL file, just use the current recording state.
41+
// It's not clear how best to map realtime to ETL QPC time, and there
42+
// aren't any realtime cues in this case.
43+
if (args.mEtlFileName == nullptr) {
44+
uint64_t qpc = 0;
45+
QueryPerformanceCounter((LARGE_INTEGER*) &qpc);
46+
gRecordingToggleHistory.emplace_back(qpc);
47+
}
48+
}
5149

52-
EnterCriticalSection(&gRecordingToggleCS);
53-
gRecordingToggleHistory.emplace_back(qpc);
54-
gIsRecording = record;
5550
LeaveCriticalSection(&gRecordingToggleCS);
5651
}
5752

@@ -233,7 +228,7 @@ static void HandleTerminatedProcess(uint32_t processId)
233228
}
234229
}
235230

236-
gProcesses.erase(iter);
231+
gProcesses.erase(std::move(iter));
237232
}
238233

239234
static void UpdateProcesses(std::vector<ProcessEvent> const& processEvents, std::vector<std::pair<uint32_t, uint64_t>>* terminatedProcesses)

Tests/PresentMon.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,24 @@ bool PresentMonCsv::Open(char const* file, int line, std::wstring const& path)
132132

133133
for (size_t i = 0, n = cols_.size(); i < n; ++i) {
134134
auto h = FindHeader(cols_[i]);
135-
if (h == UnknownHeader) {
135+
switch (h) {
136+
case KnownHeaderCount:
137+
case UnknownHeader:
136138
AddTestFailure(Convert(path_).c_str(), (int) line_, "Unrecognised column: %s", cols_[i]);
137-
} else if (headerColumnIndex_[(size_t) h] != SIZE_MAX) {
138-
AddTestFailure(Convert(path_).c_str(), (int) line_, "Duplicate column: %s", cols_[i]);
139-
} else {
140-
headerColumnIndex_[(size_t) h] = i;
141-
142-
for (auto& hg : headerGroups) {
143-
if (hg.Check(h)) {
144-
break;
139+
break;
140+
default:
141+
if (headerColumnIndex_[(size_t) h] != SIZE_MAX) {
142+
AddTestFailure(Convert(path_).c_str(), (int) line_, "Duplicate column: %s", cols_[i]);
143+
} else {
144+
headerColumnIndex_[(size_t) h] = i;
145+
146+
for (auto& hg : headerGroups) {
147+
if (hg.Check(h)) {
148+
break;
149+
}
145150
}
146151
}
152+
break;
147153
}
148154
}
149155

Tests/PresentMonTests.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88

99
bool EnsureDirectoryCreated(std::wstring path)
1010
{
11-
auto dir = path.c_str();
1211
for (auto i = path.find(L'\\');; i = path.find(L'\\', i + 1)) {
13-
if (i != std::wstring::npos) {
14-
path[i] = L'\0';
12+
std::wstring dir;
13+
if (i == std::wstring::npos) {
14+
dir = path;
15+
} else {
16+
dir = path.substr(0, i);
1517
}
1618

17-
auto attr = GetFileAttributes(dir);
19+
auto attr = GetFileAttributes(dir.c_str());
1820
if (attr == INVALID_FILE_ATTRIBUTES) {
19-
if (!CreateDirectory(dir, NULL)) {
20-
fprintf(stderr, "error: failed to create directory: %ls\n", dir);
21+
if (!CreateDirectory(dir.c_str(), NULL)) {
22+
fprintf(stderr, "error: failed to create directory: %ls\n", dir.c_str());
2123
return false;
2224
}
2325
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
24-
fprintf(stderr, "error: existing path is not a directory: %ls\n", dir);
26+
fprintf(stderr, "error: existing path is not a directory: %ls\n", dir.c_str());
2527
return false;
2628
}
2729

0 commit comments

Comments
 (0)