From b4dfc78ec2bea6b8ac7033bdadfdbdd7c120c56e Mon Sep 17 00:00:00 2001 From: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:52:49 +0200 Subject: [PATCH] Coverity fixes (#18896) * Ignore return code, we are exiting (suppress coverity) * cloud base url is now url * Suppress coverity warning * Fix coverity time_t --- src/aclk/aclk.c | 7 +++---- src/daemon/main.c | 2 +- src/database/engine/rrdengine.c | 2 +- src/database/rrd.h | 5 +++++ src/database/sqlite/sqlite_health.c | 6 ++++-- src/health/health_event_loop.c | 2 +- src/health/rrdcalc.c | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/aclk/aclk.c b/src/aclk/aclk.c index 653b2b67729cf1..7bc620a61348a4 100644 --- a/src/aclk/aclk.c +++ b/src/aclk/aclk.c @@ -171,7 +171,6 @@ static int load_private_key() */ static int wait_till_agent_claimed(void) { - //TODO prevent malloc and freez ND_UUID uuid = claim_id_get_uuid(); while (likely(UUIDiszero(uuid))) { sleep_usec(USEC_PER_SEC * 1); @@ -202,7 +201,7 @@ static int wait_till_agent_claim_ready() // We trap the impossible NULL here to keep the linter happy without using a fatal() in the code. const char *cloud_base_url = cloud_config_url_get(); if (cloud_base_url == NULL) { - netdata_log_error("Do not move the cloud base url out of post_conf_load!!"); + netdata_log_error("Do not move the \"url\" out of post_conf_load!!"); return 1; } @@ -210,7 +209,7 @@ static int wait_till_agent_claim_ready() // TODO make it without malloc/free memset(&url, 0, sizeof(url_t)); if (url_parse(cloud_base_url, &url)) { - netdata_log_error("Agent is claimed but the URL in configuration key \"cloud base url\" is invalid, please fix"); + netdata_log_error("Agent is claimed but the URL in configuration key \"url\" is invalid, please fix"); url_t_destroy(&url); sleep(5); continue; @@ -560,7 +559,7 @@ static int aclk_attempt_to_connect(mqtt_wss_client client) while (service_running(SERVICE_ACLK)) { aclk_cloud_base_url = cloud_config_url_get(); if (aclk_cloud_base_url == NULL) { - error_report("Do not move the cloud base url out of post_conf_load!!"); + error_report("Do not move the \"url\" out of post_conf_load!!"); aclk_status = ACLK_STATUS_NO_CLOUD_URL; return -1; } diff --git a/src/daemon/main.c b/src/daemon/main.c index a3ceaffd5b365c..cecc20b7396828 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -1201,7 +1201,7 @@ static void get_netdata_configured_variables() // get the hostname netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", ""); - verify_netdata_host_prefix(true); + (void) verify_netdata_host_prefix(true); char buf[HOSTNAME_MAX + 1]; if (get_hostname(buf, HOSTNAME_MAX)) diff --git a/src/database/engine/rrdengine.c b/src/database/engine/rrdengine.c index 25ebbcc2ac67ac..78ad873f7e9a7c 100644 --- a/src/database/engine/rrdengine.c +++ b/src/database/engine/rrdengine.c @@ -2075,6 +2075,6 @@ void dbengine_event_loop(void* arg) { } nd_log(NDLS_DAEMON, NDLP_DEBUG, "Shutting down dbengine thread"); - uv_loop_close(&main->loop); + (void) uv_loop_close(&main->loop); worker_unregister(); } diff --git a/src/database/rrd.h b/src/database/rrd.h index 2867717adc16b8..39874c2145e68b 100644 --- a/src/database/rrd.h +++ b/src/database/rrd.h @@ -1637,6 +1637,11 @@ static inline double rrddim_get_last_stored_value(RRDDIM *rd_dim, double *max_va return value; } +static inline uint32_t get_uint32_id() +{ + return now_realtime_sec() & UINT32_MAX; +} + // // RRD DB engine declarations diff --git a/src/database/sqlite/sqlite_health.c b/src/database/sqlite/sqlite_health.c index 1041fff36ddbfc..44cd644d87e61f 100644 --- a/src/database/sqlite/sqlite_health.c +++ b/src/database/sqlite/sqlite_health.c @@ -727,8 +727,10 @@ void sql_health_alarm_log_load(RRDHOST *host) dictionary_destroy(all_rrdcalcs); all_rrdcalcs = NULL; - if(!host->health_max_unique_id) host->health_max_unique_id = (uint32_t)now_realtime_sec(); - if(!host->health_max_alarm_id) host->health_max_alarm_id = (uint32_t)now_realtime_sec(); + if (!host->health_max_unique_id) + host->health_max_unique_id = get_uint32_id(); + if (!host->health_max_alarm_id) + host->health_max_alarm_id = get_uint32_id(); host->health_log.next_log_id = host->health_max_unique_id + 1; if (unlikely(!host->health_log.next_alarm_id || host->health_log.next_alarm_id <= host->health_max_alarm_id)) diff --git a/src/health/health_event_loop.c b/src/health/health_event_loop.c index 9c29e72b63cd44..0bf6892dd8140d 100644 --- a/src/health/health_event_loop.c +++ b/src/health/health_event_loop.c @@ -138,7 +138,7 @@ static void health_initialize_rrdhost(RRDHOST *host) { host->health.health_default_recipient = string_dup(health_globals.config.default_recipient); host->health.use_summary_for_notifications = health_globals.config.use_summary_for_notifications; - host->health_log.next_log_id = (uint32_t)now_realtime_sec(); + host->health_log.next_log_id = get_uint32_id(); host->health_log.next_alarm_id = 0; rw_spinlock_init(&host->health_log.spinlock); diff --git a/src/health/rrdcalc.c b/src/health/rrdcalc.c index bce709bf41892f..e5a26db073fe43 100644 --- a/src/health/rrdcalc.c +++ b/src/health/rrdcalc.c @@ -80,7 +80,7 @@ uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint3 alarm_id = sql_get_alarm_id(host, chart, name, next_event_id); if (!alarm_id) { if (unlikely(!host->health_log.next_alarm_id)) - host->health_log.next_alarm_id = (uint32_t)now_realtime_sec(); + host->health_log.next_alarm_id = get_uint32_id(); alarm_id = host->health_log.next_alarm_id++; } }