From 583e017f34f1bf98ab8d1223e4748551aecf6424 Mon Sep 17 00:00:00 2001 From: Sean Bright <sean@seanbright.com> Date: Fri, 19 Aug 2022 12:02:07 -0400 Subject: [PATCH] chan_dahdi.c: Resolve a format-truncation build warning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0: > chan_dahdi.c:4129:18: error: ā%sā directive output may be truncated > writing up to 255 bytes into a region of size between 242 and 252 > [-Werror=format-truncation=] This removes the error-prone sizeof(...) calculations in favor of just doubling the size of the base buffer. Change-Id: I2d276785286730d3d5d0a921bcea2e065dbf27c5 --- channels/chan_dahdi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 8ce0526f4d..b829aa43f4 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -4115,7 +4115,7 @@ static void dahdi_r2_on_context_log(openr2_context_t *r2context, openr2_log_leve { #define CONTEXT_TAG "Context - " char logmsg[256]; - char completemsg[sizeof(logmsg) + sizeof(CONTEXT_TAG) - 1]; + char completemsg[sizeof(logmsg) * 2]; vsnprintf(logmsg, sizeof(logmsg), fmt, ap); snprintf(completemsg, sizeof(completemsg), CONTEXT_TAG "%s", logmsg); dahdi_r2_write_log(level, completemsg); @@ -4128,10 +4128,11 @@ static void dahdi_r2_on_chan_log(openr2_chan_t *r2chan, openr2_log_level_t level { #define CHAN_TAG "Chan " char logmsg[256]; - char completemsg[sizeof(logmsg) + sizeof(CHAN_TAG) - 1]; + char completemsg[sizeof(logmsg) * 2]; vsnprintf(logmsg, sizeof(logmsg), fmt, ap); snprintf(completemsg, sizeof(completemsg), CHAN_TAG "%d - %s", openr2_chan_get_number(r2chan), logmsg); dahdi_r2_write_log(level, completemsg); +#undef CHAN_TAG } static int dahdi_r2_on_dnis_digit_received(openr2_chan_t *r2chan, char digit) -- GitLab