diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 28cf6f8c..33d71691 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -131,14 +131,19 @@ void SPDLOG_INLINE wincolor_sink::set_color_mode(color_mode mode) // set foreground color and return the orig console attributes (for resetting later) template std::uint16_t SPDLOG_INLINE wincolor_sink::set_foreground_color_(std::uint16_t attribs) -{ +{ CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info; - ::GetConsoleScreenBufferInfo(static_cast(out_handle_), &orig_buffer_info); + if (!::GetConsoleScreenBufferInfo(static_cast(out_handle_), &orig_buffer_info)) + { + return WHITE; + } + WORD back_color = orig_buffer_info.wAttributes; // retrieve the current background color back_color &= static_cast(~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)); // keep the background color unchanged - ::SetConsoleTextAttribute(static_cast(out_handle_), static_cast(attribs) | back_color); + auto ignored = ::SetConsoleTextAttribute(static_cast(out_handle_), static_cast(attribs) | back_color); + (void)(ignored); return static_cast(orig_buffer_info.wAttributes); // return orig attribs } @@ -147,7 +152,8 @@ template void SPDLOG_INLINE wincolor_sink::print_range_(const memory_buf_t &formatted, size_t start, size_t end) { auto size = static_cast(end - start); - ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, size, nullptr, nullptr); + auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, size, nullptr, nullptr); + (void)(ignored); } template @@ -155,7 +161,8 @@ void SPDLOG_INLINE wincolor_sink::write_to_file_(const memory_buf_ { auto size = static_cast(formatted.size()); DWORD bytes_written = 0; - ::WriteFile(static_cast(out_handle_), formatted.data(), size, &bytes_written, nullptr); + auto ignored = ::WriteFile(static_cast(out_handle_), formatted.data(), size, &bytes_written, nullptr); + (void)(ignored); } // wincolor_stdout_sink