From f7f2388121956ecb714cf643187d0717b6b77d86 Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Wed, 2 Oct 2019 10:59:48 +0000 Subject: [PATCH] Coverity 20190924 (#6941) * coverity_20190924: Fix 215633 In the switch the library stops case this pointer is NULL, so there is not necessity to processed with tests * coverity_20190924: Fix 338067 The current code tries to copy the same size of the variable, another possible solution would be to use a function to sanitize the code, I will try this first * coverity_20190924: Fix 348638 Considering that we are testing the variable value one line above The division will always happen * coverity_20190924: Fix 348640 For this specific case we do not have the possibility to have memory leak, valgrind confirms this, but I am adding a new variable here to the stack to discard the warning --- collectors/apps.plugin/apps_plugin.c | 2 +- daemon/main.c | 2 +- libnetdata/health/health.c | 3 ++- libnetdata/json/jsmn.c | 10 ++++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/collectors/apps.plugin/apps_plugin.c b/collectors/apps.plugin/apps_plugin.c index 29d38bb417a33e..4dcbd38b7d3990 100644 --- a/collectors/apps.plugin/apps_plugin.c +++ b/collectors/apps.plugin/apps_plugin.c @@ -3521,7 +3521,7 @@ static void send_collected_data_to_netdata(struct target *root, const char *type send_BEGIN(type, "uptime_avg", dt); for (w = root; w ; w = w->next) { if(unlikely(w->exposed && w->processes)) - send_SET(w->name, w->processes?(w->uptime_sum / w->processes):0); + send_SET(w->name, w->uptime_sum / w->processes); } send_END(); diff --git a/daemon/main.c b/daemon/main.c index bd0970fddc98c2..a599167f78c3d1 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -719,7 +719,7 @@ int get_system_info(struct rrdhost_system_info *system_info) { } char n[51], v[101]; snprintfz(n, 50,"%s",name); - snprintfz(v, 101,"%s",value); + snprintfz(v, 100,"%s",value); if(unlikely(rrdhost_set_system_info_variable(system_info, n, v))) { info("Unexpected environment variable %s=%s", n, v); } diff --git a/libnetdata/health/health.c b/libnetdata/health/health.c index b93de8b93e1fdc..a70f284b1f021c 100644 --- a/libnetdata/health/health.c +++ b/libnetdata/health/health.c @@ -136,7 +136,8 @@ int health_silencers_json_read_callback(JSON_ENTRY *e) else if (!strcmp(e->data.string,"DISABLE")) silencers->stype = STYPE_DISABLE_ALARMS; } else { debug(D_HEALTH, "JSON: Adding %s=%s", e->name, e->data.string); - health_silencers_addparam(e->callback_data, e->name, e->data.string); + SILENCER *test = health_silencers_addparam(e->callback_data, e->name, e->data.string); + (void)test; } break; diff --git a/libnetdata/json/jsmn.c b/libnetdata/json/jsmn.c index c8d9e73db906cc..95253589750821 100644 --- a/libnetdata/json/jsmn.c +++ b/libnetdata/json/jsmn.c @@ -301,10 +301,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, } } - for (i = parser->toknext - 1; i >= 0; i--) { - /* Unmatched opened object or array */ - if (tokens[i].start != -1 && tokens[i].end == -1) { - return JSMN_ERROR_PART; + if (tokens) { + for (i = parser->toknext - 1; i >= 0; i--) { + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } } }