From 0aff9d9d2661411410b45ea5e864537f75b49a08 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 2 Mar 2020 18:20:55 +0100 Subject: [PATCH] fix -Wstringop-trunc in phy_common helper gcc8 added a -Wstringop-truncation warning that flags an issue in phy_common because we are copying a str to another str without explicitly saying it's null-terminated. we could turn off the warning using a pragma in the code but I guess it's safe to just null-terminate after copying manually [1] https://stackoverflow.com/questions/50198319/gcc-8-wstringop-truncation-what-is-the-good-practice --- lib/src/phy/common/phy_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/phy/common/phy_common.c b/lib/src/phy/common/phy_common.c index 772536b7b..fa388308e 100644 --- a/lib/src/phy/common/phy_common.c +++ b/lib/src/phy/common/phy_common.c @@ -872,11 +872,13 @@ const char* srslte_ack_nack_feedback_mode_string(srslte_ack_nack_feedback_mode_t srslte_ack_nack_feedback_mode_t srslte_string_ack_nack_feedback_mode(const char* str) { +#define MAX_STR_LEN (8) int i = 0; - char str2[8] = {}; + char str2[MAX_STR_LEN] = {}; // Copy string in local buffer - strncpy(str2, str, sizeof(str2)); + strncpy(str2, str, MAX_STR_LEN - 1); + str2[MAX_STR_LEN - 1] = '\0'; // Convert to lower case while (str2[i] |= ' ', str2[++i])