mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-28 06:48:14 +00:00
Ensure scope_logger won't throw
Coverity pointed out that scope_logger is occasionally used in destructors. If it throws, the game will abort.
This commit is contained in:
parent
7dcb9d09f9
commit
76c814d6f7
13
src/log.cpp
13
src/log.cpp
@ -237,18 +237,23 @@ std::ostream &logger::operator()(log_domain const &domain, bool show_names, bool
|
||||
}
|
||||
}
|
||||
|
||||
void scope_logger::do_log_entry(log_domain const &domain, const std::string& str)
|
||||
void scope_logger::do_log_entry(log_domain const &domain, const std::string& str) NOEXCEPT
|
||||
{
|
||||
output_ = &debug()(domain, false, true);
|
||||
str_ = str;
|
||||
ticks_ = boost::posix_time::microsec_clock::local_time();
|
||||
try {
|
||||
ticks_ = boost::posix_time::microsec_clock::local_time();
|
||||
} catch(...) {}
|
||||
(*output_) << "{ BEGIN: " << str_ << "\n";
|
||||
++indent;
|
||||
}
|
||||
|
||||
void scope_logger::do_log_exit()
|
||||
void scope_logger::do_log_exit() NOEXCEPT
|
||||
{
|
||||
const long ticks = (boost::posix_time::microsec_clock::local_time() - ticks_).total_milliseconds();
|
||||
long ticks = 0;
|
||||
try {
|
||||
ticks = (boost::posix_time::microsec_clock::local_time() - ticks_).total_milliseconds();
|
||||
} catch(...) {}
|
||||
--indent;
|
||||
do_indent();
|
||||
if (timestamp) (*output_) << get_timestamp(time(nullptr));
|
||||
|
@ -44,6 +44,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#ifndef __func__
|
||||
#ifdef __FUNCTION__
|
||||
#define __func__ __FUNCTION__
|
||||
@ -164,8 +166,8 @@ public:
|
||||
}
|
||||
void do_indent() const;
|
||||
private:
|
||||
void do_log_entry(log_domain const &domain, const std::string& str);
|
||||
void do_log_exit();
|
||||
void do_log_entry(log_domain const &domain, const std::string& str) NOEXCEPT;
|
||||
void do_log_exit() NOEXCEPT;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user