Browse Source

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 3 years ago
parent
commit
5377adb065

+ 2 - 2
aclk/aclk_query.c

@@ -353,7 +353,7 @@ void *aclk_query_main_thread(void *ptr)
     return NULL;
 }
 
-#define TASK_LEN_MAX 16
+#define TASK_LEN_MAX 22
 void aclk_query_threads_start(struct aclk_query_threads *query_threads, mqtt_wss_client client)
 {
     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
     for (int i = 0; i < query_threads->count; i++) {
         query_threads->thread_list[i].idx = i; //thread needs to know its index for statistics
 
-        if(unlikely(snprintf(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
+        if(unlikely(snprintfz(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
             error("snprintf encoding error");
         netdata_thread_create(
             &query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, aclk_query_main_thread,

+ 2 - 2
aclk/aclk_stats.c

@@ -190,7 +190,7 @@ static void aclk_stats_cloud_req_http_type(struct aclk_metrics_per_sample *per_s
     rrdset_done(st);
 }
 
-#define MAX_DIM_NAME 16
+#define MAX_DIM_NAME 22
 static void aclk_stats_query_threads(uint32_t *queries_per_thread)
 {
     static RRDSET *st = NULL;
@@ -203,7 +203,7 @@ static void aclk_stats_query_threads(uint32_t *queries_per_thread)
             "netdata", "stats", 200009, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
 
         for (int i = 0; i < query_thread_count; i++) {
-            if (snprintf(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
+            if (snprintfz(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
                 error("snprintf encoding error");
             aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
         }

+ 2 - 2
aclk/https_client.c

@@ -47,7 +47,7 @@ static inline void http_parse_ctx_clear(http_parse_ctx *ctx) {
 #define RESP_PROTO "HTTP/1.1 "
 #define HTTP_KEYVAL_SEPARATOR ": "
 #define HTTP_HDR_BUFFER_SIZE 256
-#define PORT_STR_MAX_BYTES 7
+#define PORT_STR_MAX_BYTES 12
 
 static void process_http_hdr(http_parse_ctx *parse_ctx, const char *key, const char *val)
 {
@@ -468,7 +468,7 @@ int https_request(https_req_t *request, https_req_response_t *response) {
         goto exit_req_ctx;
     }
 
-    snprintf(connect_port_str, PORT_STR_MAX_BYTES, "%d", connect_port);
+    snprintfz(connect_port_str, PORT_STR_MAX_BYTES, "%d", connect_port);
 
     ctx->sock = connect_to_this_ip46(IPPROTO_TCP, SOCK_STREAM, connect_host, 0, connect_port_str, &timeout);
     if (ctx->sock < 0) {

+ 2 - 2
aclk/legacy/aclk_query.c

@@ -708,7 +708,7 @@ void legacy_aclk_query_threads_cleanup(struct aclk_query_threads *query_threads)
     } while (this_query);
 }
 
-#define TASK_LEN_MAX 16
+#define TASK_LEN_MAX 22
 void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads)
 {
     info("Starting %d query threads.", query_threads->count);
@@ -718,7 +718,7 @@ void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads)
     for (int i = 0; i < query_threads->count; i++) {
         query_threads->thread_list[i].idx = i; //thread needs to know its index for statistics
 
-        if(unlikely(snprintf(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
+        if(unlikely(snprintfz(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
             error("snprintf encoding error");
         netdata_thread_create(
             &query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, legacy_aclk_query_main_thread,

+ 2 - 2
aclk/legacy/aclk_stats.c

@@ -244,7 +244,7 @@ static void aclk_stats_cloud_req_cmd(struct legacy_aclk_metrics_per_sample *per_
     rrdset_done(st);
 }
 
-#define MAX_DIM_NAME 16
+#define MAX_DIM_NAME 22
 static void aclk_stats_query_threads(uint32_t *queries_per_thread)
 {
     static RRDSET *st = NULL;
@@ -257,7 +257,7 @@ static void aclk_stats_query_threads(uint32_t *queries_per_thread)
             "netdata", "stats", 200008, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
 
         for (int i = 0; i < legacy_query_thread_count; i++) {
-            if (snprintf(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
+            if (snprintfz(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
                 error("snprintf encoding error");
             legacy_aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
         }

+ 2 - 2
collectors/statsd.plugin/statsd.c

@@ -2180,8 +2180,8 @@ void *statsd_main(void *ptr) {
         statsd.histogram_percentile = 95.0;
     }
     {
-        char buffer[100 + 1];
-        snprintf(buffer, 100, "%0.1f%%", statsd.histogram_percentile);
+        char buffer[314 + 1];
+        snprintfz(buffer, 314, "%0.1f%%", statsd.histogram_percentile);
         statsd.histogram_percentile_str = strdupz(buffer);
     }
 

+ 2 - 2
database/engine/datafile.c

@@ -51,7 +51,7 @@ static void datafile_init(struct rrdengine_datafile *datafile, struct rrdengine_
 
 void generate_datafilepath(struct rrdengine_datafile *datafile, char *str, size_t maxlen)
 {
-    (void) snprintf(str, maxlen, "%s/" DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION,
+    (void) snprintfz(str, maxlen, "%s/" DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION,
                     datafile->ctx->dbfiles_path, datafile->tier, datafile->fileno);
 }
 
@@ -457,4 +457,4 @@ void finalize_data_files(struct rrdengine_instance *ctx)
         freez(datafile);
 
     }
-}
+}

+ 2 - 2
database/engine/journalfile.c

@@ -94,7 +94,7 @@ void * wal_get_transaction_buffer(struct rrdengine_worker_config* wc, unsigned s
 
 void generate_journalfilepath(struct rrdengine_datafile *datafile, char *str, size_t maxlen)
 {
-    (void) snprintf(str, maxlen, "%s/" WALFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL WALFILE_EXTENSION,
+    (void) snprintfz(str, maxlen, "%s/" WALFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL WALFILE_EXTENSION,
                     datafile->ctx->dbfiles_path, datafile->tier, datafile->fileno);
 }
 
@@ -513,4 +513,4 @@ void init_commit_log(struct rrdengine_instance *ctx)
     ctx->commit_log.buf = NULL;
     ctx->commit_log.buf_pos = 0;
     ctx->commit_log.transaction_id = 1;
-}
+}

+ 1 - 1
database/engine/metadata_log/logfile.c

@@ -6,7 +6,7 @@
 
 void generate_metadata_logfile_path(struct metadata_logfile *metalogfile, char *str, size_t maxlen)
 {
-    (void) snprintf(str, maxlen, "%s/" METALOG_PREFIX METALOG_FILE_NUMBER_PRINT_TMPL METALOG_EXTENSION,
+    (void) snprintfz(str, maxlen, "%s/" METALOG_PREFIX METALOG_FILE_NUMBER_PRINT_TMPL METALOG_EXTENSION,
                     metalogfile->ctx->rrdeng_ctx->dbfiles_path, metalogfile->starting_fileno, metalogfile->fileno);
 }
 

+ 1 - 0
web/api/web_api_v1.c

@@ -1109,6 +1109,7 @@ inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, c
 
 static int web_client_api_request_v1_aclk_state(RRDHOST *host, struct web_client *w, char *url) {
     UNUSED(url);
+    UNUSED(host);
     if (!netdata_ready) return HTTP_RESP_BACKEND_FETCH_FAILED;
 
     BUFFER *wb = w->response.data;