From 4a5bc41e8911b129857f0abb0161b025453c57a6 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 14 Feb 2021 00:20:44 +0200 Subject: [PATCH] Validate range in wincolor_sink::print_range_ --- include/spdlog/sinks/wincolor_sink-inl.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/spdlog/sinks/wincolor_sink-inl.h b/include/spdlog/sinks/wincolor_sink-inl.h index 21abca43..8324756b 100644 --- a/include/spdlog/sinks/wincolor_sink-inl.h +++ b/include/spdlog/sinks/wincolor_sink-inl.h @@ -144,9 +144,12 @@ std::uint16_t SPDLOG_INLINE wincolor_sink::set_foreground_color_(s 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); - auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, size, nullptr, nullptr); - (void)(ignored); + if (end > start) + { + auto size = static_cast(end - start); + auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, size, nullptr, nullptr); + (void)(ignored); + } } template