Fix found by PVS-Studio issues (#490)

Small changes, essentially cleanup, with no actual code logic change. 
* Ensure symbol_buffer aligned same as SYMBOL_INFO
* Use constexpr for compile-time constant
* Use = default for ctor bodies to allow compiler optimize them
* Pass string by reference to prevent copying, other smaller types we can  avoid passing by reference as the type is cheaper to copy.
This commit is contained in:
Dmitry Tsarevich 2023-05-15 16:59:44 +03:00 committed by GitHub
parent cc0fb7c1ea
commit bad9c58e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 17 additions and 16 deletions

View File

@ -92,7 +92,7 @@ namespace g3 {
ss_change.str("");
std::string old_log = _log_file_with_path;
_log_file_with_path = prospect_log;
_log_file_with_path = std::move(prospect_log);
_outptr = std::move(log_stream);
ss_change << "\n\tNew log file. The previous log file was at: ";
ss_change << old_log << "\n";

View File

@ -51,7 +51,7 @@ namespace g3 {
return prefix;
}
std::string pathSanityFix(std::string path, std::string file_name) {
std::string pathSanityFix(std::string path, const std::string &file_name) {
// Unify the delimeters,. maybe sketchy solution but it seems to work
// on at least win7 + ubuntu. All bets are off for older windows
std::replace(path.begin(), path.end(), '\\', '/');
@ -88,7 +88,7 @@ namespace g3 {
std::string createLogFileName(const std::string &verified_prefix, const std::string &logger_id) {
std::stringstream oss_name;
oss_name << verified_prefix << ".";
if( logger_id != "" ) {
if( !logger_id.empty() ) {
oss_name << logger_id << ".";
}
auto now = std::chrono::system_clock::now();

View File

@ -18,7 +18,7 @@ namespace g3 {
std::atomic<bool> value_;
public:
atomicbool(): value_ {false} {}
atomicbool(const bool& value): value_ {value} {}
atomicbool(bool value): value_ {value} {}
atomicbool(const std::atomic<bool>& value) : value_ {value.load(std::memory_order_acquire)} {}
atomicbool(const atomicbool& other): value_ {other.value_.load(std::memory_order_acquire)} {}
@ -32,9 +32,9 @@ namespace g3 {
return *this;
}
bool operator==(const atomicbool& rhs) const {
return (value_.load(std::memory_order_acquire) == rhs.value_.load(std::memory_order_acquire));
}
bool operator==(const atomicbool& rhs) const {
return (value_.load(std::memory_order_acquire) == rhs.value_.load(std::memory_order_acquire));
}
bool value() {return value_.load(std::memory_order_acquire);}
std::atomic<bool>& get() {return value_;}

View File

@ -67,8 +67,8 @@ namespace g3 {
std::string threadID() const;
void setExpression(const std::string expression) {
_expression = expression;
void setExpression(std::string expression) {
_expression = std::move(expression);
}
@ -149,6 +149,7 @@ namespace g3 {
struct FatalMessage : public LogMessage {
FatalMessage(const LogMessage& details, g3::SignalType signal_id);
FatalMessage(const FatalMessage&);
FatalMessage& operator=(const FatalMessage&) = delete;
virtual ~FatalMessage() {}
LogMessage copyToLogMessage() const;

View File

@ -34,7 +34,7 @@ class shared_queue
shared_queue(const shared_queue &other) = delete;
public:
shared_queue() {}
shared_queue() = default;
void push(T item) {
{

View File

@ -30,7 +30,7 @@ namespace g3 {
SinkHandle(std::shared_ptr<internal::Sink<T>> sink)
: _sink(sink) {}
~SinkHandle() {}
~SinkHandle() = default;
// Asynchronous call to the real sink. If the real sink is already deleted

View File

@ -49,7 +49,7 @@ namespace g3 {
/** return time representing POD struct (ref ctime + wchar) that is normally
* retrieved with std::localtime. g3::localtime is threadsafe which std::localtime is not.
* g3::localtime is probably used together with @ref g3::systemtime_now */
tm localtime(const std::time_t& time);
tm localtime(std::time_t time);
/** format string must conform to std::put_time's demands.
* WARNING: At time of writing there is only so-so compiler support for

View File

@ -164,7 +164,7 @@ namespace g3 {
#endif
, _file_path(file)
, _line(line)
, _function(function)
, _function(std::move(function))
, _level(level) {
}

View File

@ -120,7 +120,7 @@ namespace {
DWORD64 displacement64;
DWORD displacement;
char symbol_buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
alignas(SYMBOL_INFO) char symbol_buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(symbol_buffer);
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME;
@ -216,7 +216,7 @@ namespace stacktrace {
}); // Raii sym cleanup
const size_t kmax_frame_dump_size = 64;
constexpr size_t kmax_frame_dump_size = 64;
std::vector<uint64_t> frame_pointers(kmax_frame_dump_size);
// C++11: size set and values are zeroed

View File

@ -129,7 +129,7 @@ namespace g3 {
tm localtime(const std::time_t& ts) {
tm localtime(std::time_t ts) {
struct tm tm_snapshot;
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
localtime_s(&tm_snapshot, &ts); // windsows