]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_dahdi.c: Resolve a format-truncation build warning.
authorSean Bright <sean@seanbright.com>
Fri, 19 Aug 2022 16:02:07 +0000 (12:02 -0400)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Fri, 9 Sep 2022 14:39:06 +0000 (09:39 -0500)
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

index 8ce0526f4dd32429bf457fdc86f08745171da0ce..b829aa43f42c6943b7335c2dc3ea894c2c9b7021 100644 (file)
@@ -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)