Skip to content

Commit cb64e12

Browse files
authored
Merge pull request #61 from intel-innersource/coverity/fixes-2
Coverity fixes
2 parents de71bba + b9a9635 commit cb64e12

File tree

20 files changed

+163
-105
lines changed

20 files changed

+163
-105
lines changed

IntelPresentMon/AppCef/source/util/async/StoreFile.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ namespace p2c::client::util::async
2525
file << Traverse(pArgObj)["payload"].AsWString();
2626
return Result{ true, CefValueNull() };
2727
}
28-
else {
29-
auto s = std::format("Unable to open (for writing) file path: {}", filePath.string());
30-
pmlog_error(s);
31-
throw std::runtime_error{ s };
32-
}
33-
34-
return Result{ false, CefValueNull() };
28+
// if opening failed, that's an error
29+
auto s = std::format("Unable to open (for writing) file path: {}", filePath.string());
30+
pmlog_error(s);
31+
throw std::runtime_error{ s };
3532
}
3633
};
3734
}

IntelPresentMon/AppCef/source/winmain.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,22 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
206206
// name this process / thread
207207
log::IdentificationTable::AddThisProcess(str::ToWide(opt.cefType.AsOptional().value_or("main-client")));
208208
log::IdentificationTable::AddThisThread(L"main");
209-
// connect to the diagnostic layer
209+
// connect to the diagnostic layer (not generally used by appcef since we connect to logging directly)
210210
std::optional<pmapi::DiagnosticHandler> diag;
211-
if (opt.enableDiagnostic && opt.cefType && *opt.cefType == "renderer") {
212-
diag.emplace(
213-
(PM_DIAGNOSTIC_LEVEL)opt.logLevel.AsOptional().value_or(log::GlobalPolicy::Get().GetLogLevel()),
214-
PM_DIAGNOSTIC_OUTPUT_FLAGS_DEBUGGER | PM_DIAGNOSTIC_OUTPUT_FLAGS_QUEUE,
215-
[](const PM_DIAGNOSTIC_MESSAGE& msg) {
211+
try {
212+
if (opt.enableDiagnostic && opt.cefType && *opt.cefType == "renderer") {
213+
diag.emplace(
214+
(PM_DIAGNOSTIC_LEVEL)opt.logLevel.AsOptional().value_or(log::GlobalPolicy::Get().GetLogLevel()),
215+
PM_DIAGNOSTIC_OUTPUT_FLAGS_DEBUGGER | PM_DIAGNOSTIC_OUTPUT_FLAGS_QUEUE,
216+
[](const PM_DIAGNOSTIC_MESSAGE& msg) {
216217
auto ts = msg.pTimestamp ? str::ToWide(msg.pTimestamp) : std::wstring{};
217218
pmlog_(log::Level(msg.level)).note(
218219
std::format(L"@@ D I A G @@ => <{}> {}", ts, str::ToWide(msg.pText)));
219220
}
220-
);
221-
}
221+
);
222+
}
223+
} pmcatch_report;
224+
222225
// configure the logging system (partially based on command line options)
223226
ConfigureLogging();
224227

IntelPresentMon/CommonUtilities/Exception.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ namespace pmon::util
7878
std::rethrow_exception(pEx);
7979
}
8080
catch (const std::exception& e) {
81-
return std::format("[{}] {}", typeid(e).name(), e.what());
81+
try { return std::format("[{}] {}", typeid(e).name(), e.what()); }
82+
catch (...) { return {}; }
8283
}
8384
catch (...) {
8485
return "Unrecognized exception";

IntelPresentMon/CommonUtilities/Memory.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ namespace pmon::util
3333
std::unique_ptr<T>::reset(CloningUptr{ rhs }.std::unique_ptr<T>::release());
3434
return *this;
3535
}
36+
CloningUptr& operator=(CloningUptr&& rhs) noexcept
37+
{
38+
std::unique_ptr<T>::reset(rhs.release());
39+
return *this;
40+
}
41+
~CloningUptr() = default;
3642
};
3743
}

IntelPresentMon/CommonUtilities/log/BasicFileDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace pmon::util::log
3333
}
3434
void BasicFileDriver::SetFileStrategy(std::shared_ptr<IFileStrategy> pFileStrategy)
3535
{
36-
pFileStrategy_ = pFileStrategy;
36+
pFileStrategy_ = std::move(pFileStrategy);
3737
}
3838
void BasicFileDriver::Flush()
3939
{

IntelPresentMon/CommonUtilities/log/Channel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ namespace pmon::util::log
2121
friend struct QueueAccessor_;
2222
public:
2323
~ChannelInternal_();
24+
25+
ChannelInternal_(const ChannelInternal_&) = delete;
26+
ChannelInternal_& operator=(const ChannelInternal_&) = delete;
27+
2428
void Flush();
2529
void SignalExit();
2630
void DisableTraceResolution();
@@ -57,6 +61,8 @@ namespace pmon::util::log
5761
{
5862
public:
5963
Channel(std::vector<std::pair<std::string, std::shared_ptr<IChannelComponent>>> componentPtrs = {});
64+
Channel(const Channel&) = delete;
65+
Channel& operator=(const Channel&) = delete;
6066
~Channel();
6167
void Submit(Entry&&) noexcept override;
6268
void Submit(const Entry&) noexcept override;

IntelPresentMon/CommonUtilities/log/DiagnosticDriver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "DiagnosticDriver.h"
22
#include "../Exception.h"
33
#include "../win/WinAPI.h"
4+
#include "PanicLogger.h"
45
#include <iostream>
56
#include <span>
67
#include <algorithm>
@@ -19,7 +20,8 @@ namespace pmon::util::log
1920
DiagnosticDriver::~DiagnosticDriver()
2021
{
2122
dying_ = true;
22-
manualUnblockEvent_.Set();
23+
try { manualUnblockEvent_.Set(); }
24+
catch (...) { pmlog_panic_(L"Failed to set the manual unblock event"); }
2325
}
2426
void DiagnosticDriver::Submit(const Entry& e)
2527
{

IntelPresentMon/CommonUtilities/log/EntryBuilder.cpp

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ namespace pmon::util::log
5555
}
5656
EntryBuilder& EntryBuilder::mark(const TimePoint& tp) noexcept
5757
{
58-
const auto now = std::chrono::high_resolution_clock::now();
59-
const auto duration = std::chrono::duration<double, std::milli>(now - tp.value).count();
58+
try {
59+
const auto now = std::chrono::high_resolution_clock::now();
60+
const auto duration = std::chrono::duration<double, std::milli>(now - tp.value).count();
6061

61-
if (note_.empty()) {
62-
note_ += std::format(L" Marked: {:.3f}ms", duration);
63-
}
64-
else {
65-
note_ += std::format(L"\n Marked: {:.3f}ms", duration);
62+
if (note_.empty()) {
63+
note_ += std::format(L" Marked: {:.3f}ms", duration);
64+
}
65+
else {
66+
note_ += std::format(L"\n Marked: {:.3f}ms", duration);
67+
}
6668
}
69+
catch (...) { pmlog_panic_(L"Failed to mark time in EntryBuilder"); }
6770
return *this;
6871
}
6972

@@ -153,32 +156,37 @@ namespace pmon::util::log
153156
}
154157
EntryBuilder::~EntryBuilder()
155158
{
156-
if (pDest_) {
157-
auto tracing = captureTrace_.value_or((int)level_ <= (int)GlobalPolicy::Get().GetTraceLevel());
158-
// do line override check
159-
if (LineTable::GetTraceOverride()) {
160-
if (auto pEntry = LineTable::TryLookup(GetSourceFileName(), sourceLine_)) {
161-
switch (pEntry->traceOverride_) {
162-
case LineTable::TraceOverride::ForceOn: tracing = true; break;
163-
case LineTable::TraceOverride::ForceOff: tracing = false; break;
159+
try {
160+
if (pDest_) {
161+
auto tracing = captureTrace_.value_or((int)level_ <= (int)GlobalPolicy::Get().GetTraceLevel());
162+
// do line override check
163+
if (LineTable::GetTraceOverride()) {
164+
if (auto pEntry = LineTable::TryLookup(GetSourceFileName(), sourceLine_)) {
165+
switch (pEntry->traceOverride_) {
166+
case LineTable::TraceOverride::ForceOn: tracing = true; break;
167+
case LineTable::TraceOverride::ForceOff: tracing = false; break;
168+
}
164169
}
165170
}
166-
}
167-
if (tracing) {
168-
try {
169-
pTrace_ = StackTrace::Here(traceSkipDepth_);
170-
if (GlobalPolicy::Get().GetResolveTraceInClientThread()) {
171-
pTrace_->Resolve();
171+
if (tracing) {
172+
try {
173+
pTrace_ = StackTrace::Here(traceSkipDepth_);
174+
if (GlobalPolicy::Get().GetResolveTraceInClientThread()) {
175+
pTrace_->Resolve();
176+
}
177+
}
178+
catch (...) {
179+
pmlog_panic_(L"Failed to get current stacktrace");
172180
}
173181
}
174-
catch (...) {
175-
pmlog_panic_(L"Failed to get current stacktrace");
176-
}
182+
pDest_->Submit(std::move(*this));
183+
}
184+
else {
185+
pmlog_panic_(L"Log entry completed with no destination channel set");
177186
}
178-
pDest_->Submit(std::move(*this));
179187
}
180-
else {
181-
pmlog_panic_(L"Log entry completed with no destination channel set");
188+
catch (...) {
189+
pmlog_panic_(L"Error when completing log entry");
182190
}
183191
}
184192
}

IntelPresentMon/CommonUtilities/log/EntryBuilder.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <format>
44
#include <memory>
55
#include "TimePoint.h"
6+
#include "PanicLogger.h"
67

78
namespace pmon::util::log
89
{
@@ -13,15 +14,23 @@ namespace pmon::util::log
1314
public:
1415
EntryBuilder(Level lvl, const wchar_t* sourceFile, const wchar_t* sourceFunctionName, int sourceLine) noexcept;
1516
EntryBuilder(Level lvl, std::wstring sourceFile, std::wstring, int sourceLine) noexcept;
17+
18+
EntryBuilder(const EntryBuilder&) = delete;
19+
EntryBuilder & operator=(const EntryBuilder&) = delete;
20+
21+
~EntryBuilder();
1622
template<typename T>
1723
EntryBuilder& watch(const wchar_t* symbol, const T& value) noexcept
1824
{
19-
if (note_.empty()) {
20-
note_ += std::format(L" {} => {}", symbol, value);
21-
}
22-
else {
23-
note_ += std::format(L"\n {} => {}", symbol, value);
25+
try {
26+
if (note_.empty()) {
27+
note_ += std::format(L" {} => {}", symbol, value);
28+
}
29+
else {
30+
note_ += std::format(L"\n {} => {}", symbol, value);
31+
}
2432
}
33+
catch (...) { pmlog_panic_(L"Failed to format watch in EntryBuilder"); }
2534
return *this;
2635
}
2736
EntryBuilder& mark(const TimePoint& tp) noexcept;
@@ -45,7 +54,6 @@ namespace pmon::util::log
4554
errorCode_ = { code };
4655
return *this;
4756
}
48-
~EntryBuilder();
4957
private:
5058
std::shared_ptr<IEntrySink> pDest_;
5159
int traceSkipDepth_;

IntelPresentMon/CommonUtilities/log/ErrorCode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ namespace pmon::util::log
6363
ErrorCode(const ErrorCode&);
6464
ErrorCode(ErrorCode&&);
6565
ErrorCode& operator=(ErrorCode&&);
66+
67+
ErrorCode & operator=(const ErrorCode&) = delete;
68+
~ErrorCode() = default;
69+
6670
bool HasUnsigned() const;
6771
bool HasSigned() const;
6872
bool HasIntegral() const;

0 commit comments

Comments
 (0)