From 9ebb9ff3180e4c1e9dc363fa6d717be3cc3fcb98 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sun, 25 Feb 2018 00:16:18 +0100 Subject: [PATCH] readability-implicit-bool-cast --- include/spdlog/details/file_helper.h | 6 +++--- include/spdlog/details/os.h | 6 +++--- include/spdlog/sinks/file_sinks.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index dff788ff..754f6885 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -46,7 +46,6 @@ public: void open(const filename_t& fname, bool truncate = false) { - close(); auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab"); _filename = fname; @@ -76,7 +75,7 @@ public: void close() { - if (_fd) + if (_fd != nullptr) { std::fclose(_fd); _fd = nullptr; @@ -93,8 +92,9 @@ public: size_t size() const { - if (!_fd) + if (_fd == nullptr) { throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename)); + } return os::filesize(_fd); } diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index e647e32a..1f44e680 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -170,7 +170,7 @@ inline void prevent_child_fd(FILE *f) //fopen_s on non windows for writing -inline int fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode) +inline bool fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode) { #ifdef _WIN32 #ifdef SPDLOG_WCHAR_FILENAMES @@ -482,9 +482,9 @@ inline bool in_terminal(FILE* file) { #ifdef _WIN32 - return _isatty(_fileno(file)) ? true : false; + return _isatty(_fileno(file)) != 0; #else - return isatty(fileno(file)) ? true : false; + return isatty(fileno(file)) != 0; #endif } } //os diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index f4abd81b..0266f9ae 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -84,7 +84,7 @@ public: static filename_t calc_filename(const filename_t& filename, std::size_t index) { typename std::conditional::value, fmt::MemoryWriter, fmt::WMemoryWriter>::type w; - if (index) + if (index != 0u) { filename_t basename, ext; std::tie(basename, ext) = details::file_helper::split_by_extenstion(filename); @@ -136,7 +136,7 @@ private: throw spdlog_ex("rotating_file_sink: failed removing " + filename_to_str(target), errno); } } - if (details::file_helper::file_exists(src) && details::os::rename(src, target)) + if (details::file_helper::file_exists(src) && details::os::rename(src, target) != 0) { throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); }