Fix warnings from -Wformat-truncation=2 (#11676)
* mark host as UNUSED * use snprintfz instead of snprintf. removes warning: %s directive output between 0 and 4096 bytes may exceed minimum required size of 4095 * increase length to 22 to include full int length. stops warning %d directive output may be truncated writing between 1 and 11 bytes into a region of size 5 * increase buffers to stop warning %0.1f directive output may be truncated writing between 3 and 312 bytes into a region of size 100 * use sprintfz
Emmanuel Vasilakis committed
Oct 22, 2021 at 15:56 UTC
5377adb065af6d0e43973ff5f6b4344353dd1612
10 files changed
+18
-17
aclk/aclk_query.c
+2
-2
@@ -353,7 +353,7 @@ void *aclk_query_main_thread(void *ptr)
353
return NULL;
354
}
355
356
-#define TASK_LEN_MAX 16
356
+#define TASK_LEN_MAX 22
357
void aclk_query_threads_start(struct aclk_query_threads *query_threads, mqtt_wss_client client)
358
{
359
info("Starting %d query threads.", query_threads->count);
@@ -363,7 +363,7 @@ void aclk_query_threads_start(struct aclk_query_threads *query_threads, mqtt_wss
363
for (int i = 0; i < query_threads->count; i++) {
364
query_threads->thread_list[i].idx = i; //thread needs to know its index for statistics
365
366
- if(unlikely(snprintf(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
366
+ if(unlikely(snprintfz(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
367
error("snprintf encoding error");
368
netdata_thread_create(
369
&query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, aclk_query_main_thread,
aclk/aclk_stats.c
+2
-2
@@ -190,7 +190,7 @@ static void aclk_stats_cloud_req_http_type(struct aclk_metrics_per_sample *per_s
190
rrdset_done(st);
191
}
192
193
-#define MAX_DIM_NAME 16
193
+#define MAX_DIM_NAME 22
194
static void aclk_stats_query_threads(uint32_t *queries_per_thread)
195
{
196
static RRDSET *st = NULL;
@@ -203,7 +203,7 @@ static void aclk_stats_query_threads(uint32_t *queries_per_thread)
203
"netdata", "stats", 200009, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
204
205
for (int i = 0; i < query_thread_count; i++) {
206
- if (snprintf(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
206
+ if (snprintfz(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
207
error("snprintf encoding error");
208
aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
209
}
aclk/https_client.c
+2
-2
@@ -47,7 +47,7 @@ static inline void http_parse_ctx_clear(http_parse_ctx *ctx) {
47
#define RESP_PROTO "HTTP/1.1 "
48
#define HTTP_KEYVAL_SEPARATOR ": "
49
#define HTTP_HDR_BUFFER_SIZE 256
50
-#define PORT_STR_MAX_BYTES 7
50
+#define PORT_STR_MAX_BYTES 12
51
52
static void process_http_hdr(http_parse_ctx *parse_ctx, const char *key, const char *val)
53
{
@@ -468,7 +468,7 @@ int https_request(https_req_t *request, https_req_response_t *response) {
468
goto exit_req_ctx;
469
}
470
471
- snprintf(connect_port_str, PORT_STR_MAX_BYTES, "%d", connect_port);
471
+ snprintfz(connect_port_str, PORT_STR_MAX_BYTES, "%d", connect_port);
472
473
ctx->sock = connect_to_this_ip46(IPPROTO_TCP, SOCK_STREAM, connect_host, 0, connect_port_str, &timeout);
474
if (ctx->sock < 0) {
aclk/legacy/aclk_query.c
+2
-2
@@ -708,7 +708,7 @@ void legacy_aclk_query_threads_cleanup(struct aclk_query_threads *query_threads)
708
} while (this_query);
709
}
710
711
-#define TASK_LEN_MAX 16
711
+#define TASK_LEN_MAX 22
712
void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads)
713
{
714
info("Starting %d query threads.", query_threads->count);
@@ -718,7 +718,7 @@ void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads)
718
for (int i = 0; i < query_threads->count; i++) {
719
query_threads->thread_list[i].idx = i; //thread needs to know its index for statistics
720
721
- if(unlikely(snprintf(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
721
+ if(unlikely(snprintfz(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
722
error("snprintf encoding error");
723
netdata_thread_create(
724
&query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, legacy_aclk_query_main_thread,
aclk/legacy/aclk_stats.c
+2
-2
@@ -244,7 +244,7 @@ static void aclk_stats_cloud_req_cmd(struct legacy_aclk_metrics_per_sample *per_
244
rrdset_done(st);
245
}
246
247
-#define MAX_DIM_NAME 16
247
+#define MAX_DIM_NAME 22
248
static void aclk_stats_query_threads(uint32_t *queries_per_thread)
249
{
250
static RRDSET *st = NULL;
@@ -257,7 +257,7 @@ static void aclk_stats_query_threads(uint32_t *queries_per_thread)
257
"netdata", "stats", 200008, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
258
259
for (int i = 0; i < legacy_query_thread_count; i++) {
260
- if (snprintf(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
260
+ if (snprintfz(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
261
error("snprintf encoding error");
262
legacy_aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
263
}
collectors/statsd.plugin/statsd.c
+2
-2
@@ -2180,8 +2180,8 @@ void *statsd_main(void *ptr) {
2180
statsd.histogram_percentile = 95.0;
2181
}
2182
{
2183
- char buffer[100 + 1];
2184
- snprintf(buffer, 100, "%0.1f%%", statsd.histogram_percentile);
2183
+ char buffer[314 + 1];
2184
+ snprintfz(buffer, 314, "%0.1f%%", statsd.histogram_percentile);
2185
statsd.histogram_percentile_str = strdupz(buffer);
2186
}
2187
database/engine/datafile.c
+2
-2
@@ -51,7 +51,7 @@ static void datafile_init(struct rrdengine_datafile *datafile, struct rrdengine_
51
52
void generate_datafilepath(struct rrdengine_datafile *datafile, char *str, size_t maxlen)
53
{
54
- (void) snprintf(str, maxlen, "%s/" DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION,
54
+ (void) snprintfz(str, maxlen, "%s/" DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION,
55
datafile->ctx->dbfiles_path, datafile->tier, datafile->fileno);
56
}
57
@@ -457,4 +457,4 @@ void finalize_data_files(struct rrdengine_instance *ctx)
457
freez(datafile);
458
459
}
460
-}
\ No newline at end of file
460
+}
database/engine/journalfile.c
+2
-2
@@ -94,7 +94,7 @@ void * wal_get_transaction_buffer(struct rrdengine_worker_config* wc, unsigned s
94
95
void generate_journalfilepath(struct rrdengine_datafile *datafile, char *str, size_t maxlen)
96
{
97
- (void) snprintf(str, maxlen, "%s/" WALFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL WALFILE_EXTENSION,
97
+ (void) snprintfz(str, maxlen, "%s/" WALFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL WALFILE_EXTENSION,
98
datafile->ctx->dbfiles_path, datafile->tier, datafile->fileno);
99
}
100
@@ -513,4 +513,4 @@ void init_commit_log(struct rrdengine_instance *ctx)
513
ctx->commit_log.buf = NULL;
514
ctx->commit_log.buf_pos = 0;
515
ctx->commit_log.transaction_id = 1;
516
-}
\ No newline at end of file
516
+}
database/engine/metadata_log/logfile.c
+1
-1
@@ -6,7 +6,7 @@
6
7
void generate_metadata_logfile_path(struct metadata_logfile *metalogfile, char *str, size_t maxlen)
8
{
9
- (void) snprintf(str, maxlen, "%s/" METALOG_PREFIX METALOG_FILE_NUMBER_PRINT_TMPL METALOG_EXTENSION,
9
+ (void) snprintfz(str, maxlen, "%s/" METALOG_PREFIX METALOG_FILE_NUMBER_PRINT_TMPL METALOG_EXTENSION,
10
metalogfile->ctx->rrdeng_ctx->dbfiles_path, metalogfile->starting_fileno, metalogfile->fileno);
11
}
12
web/api/web_api_v1.c
+1
@@ -1109,6 +1109,7 @@ inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, c
1109
1110
static int web_client_api_request_v1_aclk_state(RRDHOST *host, struct web_client *w, char *url) {
1111
UNUSED(url);
1112
+ UNUSED(host);
1113
if (!netdata_ready) return HTTP_RESP_BACKEND_FETCH_FAILED;
1114
1115
BUFFER *wb = w->response.data;