diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h index eeb56bae..4f626afe 100644 --- a/include/spdlog/sinks/systemd_sink.h +++ b/include/spdlog/sinks/systemd_sink.h @@ -44,16 +44,23 @@ protected: { int err; + size_t length = msg.payload.size(); + // limit to max int + if(length > std::numeric_limits::max()) + { + length = std::numeric_limits::max(); + } + // Do not send source location if not available if (msg.source.empty()) { // Note: function call inside '()' to avoid macro expansion err = (sd_journal_send)( - "MESSAGE=%.*s", static_cast(msg.payload.size()), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr); + "MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr); } else { - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(msg.payload.size()), msg.payload.data(), "PRIORITY=%d", + err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), "SOURCE_FILE=%s", msg.source.filename, "SOURCE_LINE=%d", msg.source.line, "SOURCE_FUNC=%s", msg.source.funcname, nullptr); }