From 847f7de00317c76ebb43b09b6125b8a3496c99c5 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 10 Jul 2019 02:19:16 +0300 Subject: [PATCH] Simplify syslog sinks overflow check --- include/spdlog/sinks/syslog_sink.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index ccc70693..a160c10d 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -59,8 +59,14 @@ protected: payload = msg.payload; } - int length = std::min::type>(std::numeric_limits::max(), payload.size()); - ::syslog(syslog_prio_from_level(msg), "%.*s", length, payload.data()); + size_t length = payload.size(); + // limit to max int + if(length > std::numeric_limits::max()) + { + length = std::numeric_limits::max(); + } + + ::syslog(syslog_prio_from_level(msg), "%.*s", static_cast(length), payload.data()); } void flush_() override {}