summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-05-24 21:08:10 +0200
committerSébastien Helleu <flashcode@flashtux.org>2024-05-24 21:08:10 +0200
commit52942495153978156a0832d8898ff4d7b732c6a8 (patch)
tree9168915d25385fecd995f7e80ffef36edab6b5ac
parent2b81cce9e06e4809b7a84fb658f5716a4da823cd (diff)
downloadweechat-52942495153978156a0832d8898ff4d7b732c6a8.zip
relay: fix compiler warning in call to snprintf
This fixes the following warning emitted by gcc: …/relay-http.c:1207:32: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size 64 [-Wformat-truncation=] 1207 | "%s[%d bytes data]", | ^~ 1208 | str_header, | ~~~~~~~~~~ …/relay-http.c:1207:31: note: directive argument in the range [1, 2147483647] 1207 | "%s[%d bytes data]", | ^~~~~~~~~~~~~~~~~~~ …/relay-http.c:1206:21: note: ‘snprintf’ output between 15 and 1047 bytes into a destination of size 64 1206 | snprintf (raw_message, length_raw, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1207 | "%s[%d bytes data]", | ~~~~~~~~~~~~~~~~~~~~ 1208 | str_header, | ~~~~~~~~~~~ 1209 | *ptr_body_size); | ~~~~~~~~~~~~~~~
-rw-r--r--src/plugins/relay/relay-http.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/plugins/relay/relay-http.c b/src/plugins/relay/relay-http.c
index 5069eabdd..63f803389 100644
--- a/src/plugins/relay/relay-http.c
+++ b/src/plugins/relay/relay-http.c
@@ -1147,7 +1147,7 @@ relay_http_send (struct t_relay_client *client,
const char *ptr_body;
char str_header[1024], str_content_encoding[256];
char *compressed_body, *http_message, *raw_message;
- int length_header, length_msg, length_raw, num_bytes;
+ int length_header, length_msg, num_bytes;
int *ptr_body_size, compressed_body_size;
if (!client || !message || (body_size < 0))
@@ -1197,21 +1197,13 @@ relay_http_send (struct t_relay_client *client,
memcpy (http_message, str_header, length_header);
memcpy (http_message + length_header, ptr_body, *ptr_body_size);
http_message[length_msg] = '\0';
+ raw_message = NULL;
if (compressed_body)
{
- length_raw = strlen (str_header) + 64;
- raw_message = malloc (length_raw);
- if (raw_message)
- {
- snprintf (raw_message, length_raw,
- "%s[%d bytes data]",
- str_header,
- *ptr_body_size);
- }
- }
- else
- {
- raw_message = NULL;
+ weechat_asprintf (&raw_message,
+ "%s[%d bytes data]",
+ str_header,
+ *ptr_body_size);
}
num_bytes = relay_client_send (client, RELAY_MSG_STANDARD,
http_message, length_msg,