From 4f1db81e277df1a23c61eaa6ec9784e84aa43547 Mon Sep 17 00:00:00 2001 From: Kaian Date: Mon, 25 Oct 2021 16:28:47 +0200 Subject: [PATCH] gcc: remove format-truncation compilation warnings --- src/curses/ui_call_flow.c | 4 ++-- src/curses/ui_filter.c | 4 ++-- src/sip.c | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/curses/ui_call_flow.c b/src/curses/ui_call_flow.c index b2db6c9..9209c6e 100644 --- a/src/curses/ui_call_flow.c +++ b/src/curses/ui_call_flow.c @@ -465,12 +465,12 @@ call_flow_draw_message(ui_t *ui, call_flow_arrow_t *arrow, int cline) timeval_to_time(msg_get_time(msg), msg_time); // Get Message method (include extra info) - snprintf(method, METHOD_MAXLEN, "%s", msg_method); + snprintf(method, METHOD_MAXLEN, "%.*s", METHOD_MAXLEN-1, msg_method); // If message has sdp information if (msg_has_sdp(msg) && setting_has_value(SETTING_CF_SDP_INFO, "off")) { // Show sdp tag in title - snprintf(method, METHOD_MAXLEN, "%s (SDP)", msg_method ); + snprintf(method, METHOD_MAXLEN, "%.*s (SDP)", METHOD_MAXLEN-7, msg_method ); } // If message has sdp information diff --git a/src/curses/ui_filter.c b/src/curses/ui_filter.c index 6528f74..9ad9a55 100644 --- a/src/curses/ui_filter.c +++ b/src/curses/ui_filter.c @@ -444,7 +444,7 @@ filter_field_method(int field_id) void filter_method_from_setting(const char *value) { - char methods[256], method_expr[256]; + char methods[250], method_expr[256]; int methods_len = strlen(value); char *comma; @@ -459,7 +459,7 @@ filter_method_from_setting(const char *value) // Create a regular expression memset(method_expr, 0, sizeof(method_expr)); - sprintf(method_expr, "(%s)", methods); + snprintf(method_expr, sizeof(method_expr), "(%s)", methods); filter_set(FILTER_METHOD, method_expr); } else { filter_set(FILTER_METHOD, " "); diff --git a/src/sip.c b/src/sip.c index 5d00454..643176c 100644 --- a/src/sip.c +++ b/src/sip.c @@ -543,7 +543,7 @@ sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload) // Method & CSeq if (regexec(&calls.reg_method, (const char *)payload, 2, pmatch, 0) == 0) { if ((int)(pmatch[1].rm_eo - pmatch[1].rm_so) >= SIP_ATTR_MAXLEN) { - strncpy(reqresp, "", 11); + strncpy(reqresp, "", 12); } else { sprintf(reqresp, "%.*s", (int) (pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); } @@ -559,12 +559,12 @@ sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload) // Response code if (regexec(&calls.reg_response, (const char *)payload, 3, pmatch, 0) == 0) { if ((int)(pmatch[1].rm_eo - pmatch[1].rm_so) >= SIP_ATTR_MAXLEN) { - strncpy(resp_str, "", 11); + strncpy(resp_str, "", 12); } else { sprintf(resp_str, "%.*s", (int) (pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); } if ((int)(pmatch[2].rm_eo - pmatch[2].rm_so) >= SIP_ATTR_MAXLEN) { - strncpy(resp_str, "", 11); + strncpy(resp_str, "", 12); } else { sprintf(reqresp, "%.*s", (int) (pmatch[2].rm_eo - pmatch[2].rm_so), payload + pmatch[2].rm_so); } @@ -617,7 +617,7 @@ sip_parse_msg_payload(sip_msg_t *msg, const u_char *payload) } else { // Malformed From Header msg->sip_from = sng_malloc(12); - strncpy(msg->sip_from, "", 11); + strncpy(msg->sip_from, "", 12); } // To @@ -627,7 +627,7 @@ sip_parse_msg_payload(sip_msg_t *msg, const u_char *payload) } else { // Malformed To Header msg->sip_to = sng_malloc(12); - strncpy(msg->sip_to, "", 11); + strncpy(msg->sip_to, "", 12); } return 0;