Skip to content

Commit 03274cb

Browse files
committed
Merge branch 'coverity/analysis-fixes-1'
2 parents cb64e12 + 1cda459 commit 03274cb

File tree

7 files changed

+55
-35
lines changed

7 files changed

+55
-35
lines changed

IntelPresentMon/InterprocessMock/Main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ int main(int argc, char** argv)
301301
std::cout << "Invalid Dynamic Cast Exception: " << e.what();
302302
return -1;
303303
}
304-
305-
304+
catch (const CLI::BadNameString& e)
305+
{
306+
return e.get_exit_code();
307+
}
306308

307309
return 0;
308310
}

IntelPresentMon/PresentMonAPI2Tests/CsvHelper.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ constexpr char const* GetHeaderString(Header h)
137137
case Header_DwmNotified: return "DwmNotified";
138138
default: return "<unknown>";
139139
}
140-
return "<unknown>";
141140
}
142141

143142
std::wstring CreateErrorString(Header columnId, size_t line)
@@ -316,7 +315,7 @@ class CsvParser {
316315
size_t line_ = 0;
317316
std::vector<char const*> cols_;
318317
v2Metrics v2MetricRow_;
319-
uint32_t processId_;
318+
uint32_t processId_ = 0;
320319
std::map<size_t, Header> activeColHeadersMap_;
321320
};
322321

@@ -502,11 +501,11 @@ bool CsvParser::FindFirstRowWithPid(const unsigned int& searchProcessId)
502501
char const* processIdString = nullptr;
503502
if (processColIdx < cols_.size()) {
504503
processIdString = cols_[Header_ProcessID];
505-
}
506-
unsigned int currentProcessId = 0;
507-
int succeededCount = sscanf_s(processIdString, "%ud", &currentProcessId);
508-
if (searchProcessId == currentProcessId) {
509-
return true;
504+
unsigned int currentProcessId = 0;
505+
int succeededCount = sscanf_s(processIdString, "%ud", &currentProcessId);
506+
if (searchProcessId == currentProcessId) {
507+
return true;
508+
}
510509
}
511510
}
512511
}
@@ -552,15 +551,21 @@ bool CsvParser::Open(std::wstring const& path, uint32_t processId) {
552551
case UnknownHeader:
553552
Assert::Fail(CreateErrorString(h, line_).c_str());
554553
default:
555-
if (headerColumnIndex_[(size_t)h] != SIZE_MAX) {
556-
std::wstring errorMessage = L"Duplicate column: ";
557-
errorMessage += pmon::util::str::ToWide(cols_[i]);
558-
Assert::Fail(errorMessage.c_str());
554+
if ((size_t)h < KnownHeaderCount) {
555+
if (headerColumnIndex_[(size_t)h] != SIZE_MAX) {
556+
std::wstring errorMessage = L"Duplicate column: ";
557+
errorMessage += pmon::util::str::ToWide(cols_[i]);
558+
Assert::Fail(errorMessage.c_str());
559+
}
560+
else {
561+
headerColumnIndex_[(size_t)h] = i;
562+
}
563+
break;
559564
}
560565
else {
561-
headerColumnIndex_[(size_t)h] = i;
566+
std::wstring errorMessage = L"Index outside of known headers.";
567+
Assert::Fail(errorMessage.c_str());
562568
}
563-
break;
564569
}
565570
}
566571

IntelPresentMon/PresentMonAPI2Tests/RealtimeMetricTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace RealtimeMetricTests
182182

183183
std::wstring appName = L"PresentBench.exe";
184184
std::optional<unsigned int> appPid;
185-
GetProcessInformation(appName, appPid);
185+
GetProcessInformation(std::move(appName), appPid);
186186
if (!appPid.has_value())
187187
{
188188
Assert::AreEqual(false, true, L"*** Unable to detect PresentBench.exe.");
@@ -241,7 +241,7 @@ namespace RealtimeMetricTests
241241

242242
std::wstring appName = L"PresentBench.exe";
243243
std::optional<unsigned int> appPid;
244-
GetProcessInformation(appName, appPid);
244+
GetProcessInformation(std::move(appName), appPid);
245245
if (!appPid.has_value())
246246
{
247247
Assert::AreEqual(false, true, L"*** Unable to detect PresentBench.exe.");

IntelPresentMon/PresentMonAPIWrapper/DiagnosticHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ namespace pmapi
3232
// capture source file and line number as a string
3333
bool enableLocation = false
3434
);
35+
DiagnosticHandler(const DiagnosticHandler& other) = delete;
36+
DiagnosticHandler(DiagnosticHandler&& other) = delete;
37+
DiagnosticHandler& operator=(const DiagnosticHandler& other) = delete;
3538
~DiagnosticHandler();
3639
private:
3740
std::shared_ptr<void> pImpl;

IntelPresentMon/SampleClient/DiagnosticDemo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ void RunDiagnosticDemo(int mode)
3838

3939
// basic log info w/ message
4040
if (mode == 0) {
41+
std::string timeStamp = std::format("{}", std::chrono::zoned_time{ std::chrono::current_zone(), std::chrono::system_clock::now() });
4142
PM_DIAGNOSTIC_MESSAGE dm{
4243
.level = PM_DIAGNOSTIC_LEVEL_WARNING,
4344
.system = PM_DIAGNOSTIC_SUBSYSTEM(PM_DIAGNOSTIC_SUBSYSTEM_USER + 2),
4445
.pText = "@#$ test test test",
45-
.pTimestamp = std::format("{}", std::chrono::zoned_time{ std::chrono::current_zone(), std::chrono::system_clock::now() }).c_str(),
46+
.pTimestamp = timeStamp.c_str(),
4647
};
4748
pmDiagnosticEnqueueMessage(&dm);
4849
}

IntelPresentMon/SampleClient/LogSetup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace p2sam
88
{
99
LogChannelManager() noexcept;
1010
~LogChannelManager();
11+
LogChannelManager(const LogChannelManager& other) = delete;
12+
LogChannelManager(LogChannelManager&& other) = delete;
13+
LogChannelManager& operator=(const LogChannelManager& other) = delete;
1114
};
1215
// call after command line arguments have been parsed
1316
void ConfigureLogging() noexcept;

PresentData/PresentMonTraceConsumer.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,21 +1918,26 @@ void PMTraceConsumer::AddPresentToCompletedList(std::shared_ptr<PresentEvent> co
19181918
}
19191919

19201920
UpdateReadyCount(present);
1921-
1922-
// It's possible for a deferred condition to never be cleared. e.g., a process' last present
1923-
// doesn't get a Present_Stop event. When this happens the deferred present will prevent all
1924-
// subsequent presents from other processes from being dequeued until the ring buffer wraps and
1925-
// forces it out, which is likely longer than we want to wait. So we check here if there is
1926-
// a stuck deferred present and clear the deferral if it gets too old.
1927-
if (mReadyCount == 0) {
1928-
auto const& deferredPresent = mCompletedPresents[mCompletedIndex];
1929-
if (present->PresentStartTime >= deferredPresent->PresentStartTime &&
1930-
present->PresentStartTime - deferredPresent->PresentStartTime > mDeferralTimeLimit) {
1931-
VerboseTraceBeforeModifyingPresent(deferredPresent.get());
1932-
deferredPresent->IsLost = true;
1933-
deferredPresent->WaitingForPresentStop = false;
1934-
deferredPresent->WaitingForFlipFrameType = false;
1935-
UpdateReadyCount(deferredPresent);
1921+
1922+
{
1923+
std::unique_lock<std::mutex> lock(mPresentEventMutex);
1924+
// It's possible for a deferred condition to never be cleared. e.g., a process' last present
1925+
// doesn't get a Present_Stop event. When this happens the deferred present will prevent all
1926+
// subsequent presents from other processes from being dequeued until the ring buffer wraps and
1927+
// forces it out, which is likely longer than we want to wait. So we check here if there is
1928+
// a stuck deferred present and clear the deferral if it gets too old.
1929+
if (mReadyCount == 0) {
1930+
auto const& deferredPresent = mCompletedPresents[mCompletedIndex];
1931+
if (present->PresentStartTime >= deferredPresent->PresentStartTime &&
1932+
present->PresentStartTime - deferredPresent->PresentStartTime > mDeferralTimeLimit) {
1933+
VerboseTraceBeforeModifyingPresent(deferredPresent.get());
1934+
deferredPresent->IsLost = true;
1935+
deferredPresent->WaitingForPresentStop = false;
1936+
deferredPresent->WaitingForFlipFrameType = false;
1937+
// UpdateReadyCount also locks the mPresentEventMutex so unlock here
1938+
lock.unlock();
1939+
UpdateReadyCount(deferredPresent);
1940+
}
19361941
}
19371942
}
19381943
}
@@ -2379,9 +2384,10 @@ void PMTraceConsumer::DequeueProcessEvents(std::vector<ProcessEvent>& outProcess
23792384
void PMTraceConsumer::DequeuePresentEvents(std::vector<std::shared_ptr<PresentEvent>>& outPresentEvents)
23802385
{
23812386
outPresentEvents.clear();
2382-
if (mReadyCount > 0) {
2383-
std::lock_guard<std::mutex> lock(mPresentEventMutex);
23842387

2388+
std::lock_guard<std::mutex> lock(mPresentEventMutex);
2389+
2390+
if (mReadyCount > 0) {
23852391
outPresentEvents.resize(mReadyCount, nullptr);
23862392
for (uint32_t i = 0; i < mReadyCount; ++i) {
23872393
std::swap(outPresentEvents[i], mCompletedPresents[mCompletedIndex]);

0 commit comments

Comments
 (0)