From 76c814d6f76d26642f652d1e499b15a87f3f7331 Mon Sep 17 00:00:00 2001 From: Alexander van Gessel Date: Tue, 12 Sep 2017 17:01:41 +0200 Subject: [PATCH] Ensure scope_logger won't throw Coverity pointed out that scope_logger is occasionally used in destructors. If it throws, the game will abort. --- src/log.cpp | 13 +++++++++---- src/log.hpp | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 11a6a5e90b3..447b4919e52 100644 --- a/src/log.cpp +++ b/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)); diff --git a/src/log.hpp b/src/log.hpp index 658c486a5f1..1e74424ab9a 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -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; }; /**