From d9a655efce161398e3250a2bad74e7648e00655d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 24 Aug 2019 12:16:41 +0200 Subject: [PATCH] Avoid truncation or bad formatting in message header --- src/algorithms/PVT/libs/rtcm.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/algorithms/PVT/libs/rtcm.h b/src/algorithms/PVT/libs/rtcm.h index 0cbba9d07..794ca2126 100644 --- a/src/algorithms/PVT/libs/rtcm.h +++ b/src/algorithms/PVT/libs/rtcm.h @@ -594,11 +594,7 @@ private: inline void encode_header() { char header[header_length + 1] = ""; - int num_chars = std::snprintf(header, header_length + 1, "GS%4d", std::min(static_cast(body_length_), static_cast(max_body_length))); - if ((num_chars <= 0) or (num_chars > header_length)) - { - // avoid Wformat-truncation warning - } + std::snprintf(header, header_length + 1, "GS%4d", std::max(std::min(static_cast(body_length_), static_cast(max_body_length)), 0)); std::memcpy(data_, header, header_length); }