From 51a65d62d01a3086caf62c912d24b54a3dcf2f07 Mon Sep 17 00:00:00 2001 From: Marek Schimara Date: Mon, 27 Jun 2016 11:04:37 +0200 Subject: [PATCH] fix style src/rrd_cgi.c src/rrd_create.c src/rrd_daemon.c src/rrd_dump.c src/rrd_fetch.c src/rrd_first.c src/rrd_flushcached.c src/rrd_graph_helper.c src/rrd_info.c src/rrd_last.c src/rrd_lastupdate.c src/rrd_update.c --- src/rrd_cgi.c | 11 +++++++---- src/rrd_create.c | 4 +++- src/rrd_daemon.c | 3 ++- src/rrd_dump.c | 15 +++++++++++---- src/rrd_fetch.c | 39 +++++++++++++++++++++++++++++---------- src/rrd_first.c | 19 ++++++++++++++----- src/rrd_flushcached.c | 8 ++++++-- src/rrd_graph_helper.c | 3 ++- src/rrd_info.c | 19 ++++++++++++++----- src/rrd_last.c | 15 +++++++++++---- src/rrd_lastupdate.c | 15 +++++++++++---- src/rrd_update.c | 7 +++++-- 12 files changed, 115 insertions(+), 43 deletions(-) diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c index d1ebbb64..12e5eecf 100644 --- a/src/rrd_cgi.c +++ b/src/rrd_cgi.c @@ -1407,7 +1407,7 @@ s_var **rrdcgiReadVariables( if ((line = (char *) malloc(length + 2)) == NULL) return NULL; if (fgets(line, length + 1, stdin) == NULL) { - free(line); + free(line); return NULL; } } else @@ -1435,8 +1435,9 @@ s_var **rrdcgiReadVariables( strncat(line, tmp, tmplen); } else { /* clean-up the storage allocated in previous iteration */ - if (line) + if (line) { free(line); + } if ((line = strdup(tmp)) == NULL) return NULL; @@ -1444,8 +1445,9 @@ s_var **rrdcgiReadVariables( } memset(tmp, 0, sizeof(tmp)); } - if (!line) + if (!line) { return NULL; + } if (line[strlen(line) - 1] == '&') line[strlen(line) - 1] = '\0'; } @@ -1577,8 +1579,9 @@ s_cgi *rrdcgiInit( s_cgi *res; s_var **vars; - if ((res = (s_cgi *) malloc(sizeof(s_cgi))) == NULL) + if ((res = (s_cgi *) malloc(sizeof(s_cgi))) == NULL) { return NULL; + } vars = rrdcgiReadVariables(); diff --git a/src/rrd_create.c b/src/rrd_create.c index 1c11ac79..c189855b 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -238,7 +238,9 @@ done: free(template); template = NULL; } - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return rc; } diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 87eb0520..115ebb41 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -2373,8 +2373,9 @@ done: free(file); free(sources); free(file_copy); - if (dir) + if (dir) { free(dir); + } free(dir2); return rc; } /* }}} static int handle_request_create */ diff --git a/src/rrd_dump.c b/src/rrd_dump.c index 6aaa0962..957ad858 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -540,8 +540,9 @@ int rrd_dump( while ((opt = optparse_long(&options, longopts, NULL)) != -1) { switch (opt) { case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup(options.optarg); if (opt_daemon == NULL) { @@ -569,7 +570,9 @@ int rrd_dump( "[--no-header|-n]\n" "[--daemon|-d address]\n" "file.rrd [file.xml]", options.argv[0]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (-1); break; } @@ -580,12 +583,16 @@ int rrd_dump( "[--no-header|-n]\n" "[--daemon|-d address]\n" "file.rrd [file.xml]", options.argv[0]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (-1); } rc = rrdc_flush_if_daemon(opt_daemon, options.argv[options.optind]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } if (rc) return (rc); if ((options.argc - options.optind) == 2) { diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 0256af8e..9466d615 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -101,14 +101,18 @@ int rrd_fetch( case 's': if ((parsetime_error = rrd_parsetime(options.optarg, &start_tv))) { rrd_set_error("start time: %s", parsetime_error); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } break; case 'e': if ((parsetime_error = rrd_parsetime(options.optarg, &end_tv))) { rrd_set_error("end time: %s", parsetime_error); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } break; @@ -118,14 +122,17 @@ int rrd_fetch( case 'r': if ((parsetime_error = rrd_scaled_duration(options.optarg, 1, &step_tmp))) { rrd_set_error("resolution: %s", parsetime_error); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } break; case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup(options.optarg); if (opt_daemon == NULL) { @@ -136,20 +143,26 @@ int rrd_fetch( case '?': rrd_set_error("%s", options.errmsg); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } } if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) { - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } if (start_tmp < 3600 * 24 * 365 * 10) { rrd_set_error("the first entry to fetch should be after 1980"); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (-1); } @@ -162,7 +175,9 @@ int rrd_fetch( if (end_tmp < start_tmp) { rrd_set_error("start (%ld) should be less than end (%ld)", start_tmp, end_tmp); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (-1); } @@ -172,7 +187,9 @@ int rrd_fetch( if (options.optind + 1 >= options.argc) { rrd_set_error("Usage: rrdtool %s [options]", options.argv[0]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } @@ -187,7 +204,9 @@ int rrd_fetch( status = rrd_fetch_r(options.argv[options.optind], cf, start, end, step, ds_cnt, ds_namv, data); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } if (status != 0) return (-1); return (0); diff --git a/src/rrd_first.c b/src/rrd_first.c index 2c68f479..7beb5842 100644 --- a/src/rrd_first.c +++ b/src/rrd_first.c @@ -33,13 +33,16 @@ time_t rrd_first( target_rraindex = strtol(options.optarg, &endptr, 0); if (target_rraindex < 0) { rrd_set_error("invalid rraindex number"); - if (opt_daemon != NULL) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return (-1); } break; case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup(options.optarg); if (opt_daemon == NULL) { @@ -49,7 +52,9 @@ time_t rrd_first( break; case '?': rrd_set_error("%s", options.errmsg); - if (opt_daemon != NULL) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return -1; } } @@ -63,10 +68,14 @@ time_t rrd_first( rrdc_connect (opt_daemon); if (rrdc_is_connected (opt_daemon)) { - if (opt_daemon != NULL) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return rrdc_first(options.argv[options.optind], target_rraindex); } else { - if (opt_daemon != NULL) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return rrd_first_r(options.argv[options.optind], target_rraindex); } } diff --git a/src/rrd_flushcached.c b/src/rrd_flushcached.c index 515b84bd..5de12787 100644 --- a/src/rrd_flushcached.c +++ b/src/rrd_flushcached.c @@ -51,7 +51,9 @@ int rrd_flushcached (int argc, char **argv) case '?': rrd_set_error("%s", options.errmsg); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } } /* while (opt!=-1) */ @@ -60,7 +62,9 @@ int rrd_flushcached (int argc, char **argv) { rrd_set_error("Usage: rrdtool %s [--daemon|-d ] [ ...]", options.argv[0]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } diff --git a/src/rrd_graph_helper.c b/src/rrd_graph_helper.c index 7b2a796c..4afd51d4 100644 --- a/src/rrd_graph_helper.c +++ b/src/rrd_graph_helper.c @@ -140,8 +140,9 @@ int getMappedKeyValueArgument(const char* key,int flag, parsedargs_t* pa, } int getLong(const char* v,long *val,char**extra,int base) { - if (extra == NULL) + if (extra == NULL) { return 0; + } /* try to execute the parser */ /* NOTE that this may be a bit different from the original parser */ diff --git a/src/rrd_info.c b/src/rrd_info.c index da60ef32..c1a08806 100644 --- a/src/rrd_info.c +++ b/src/rrd_info.c @@ -104,8 +104,9 @@ rrd_info_t *rrd_info( while ((opt = optparse_long(&options, longopts, NULL)) != -1) { switch (opt) { case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup(options.optarg); if (opt_daemon == NULL) { @@ -120,7 +121,9 @@ rrd_info_t *rrd_info( case '?': rrd_set_error("%s", options.errmsg); - if (opt_daemon) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return NULL; } } /* while (opt != -1) */ @@ -128,14 +131,18 @@ rrd_info_t *rrd_info( if (options.argc - options.optind != 1) { rrd_set_error ("Usage: rrdtool %s [--daemon |-d [--noflush|-F]] ", options.argv[0]); - if (opt_daemon) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return NULL; } if (flushfirst) { status = rrdc_flush_if_daemon(opt_daemon, options.argv[options.optind]); if (status) { - if (opt_daemon) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return (NULL); } } @@ -146,7 +153,9 @@ rrd_info_t *rrd_info( else info = rrd_info_r(options.argv[options.optind]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (info); } /* rrd_info_t *rrd_info */ diff --git a/src/rrd_last.c b/src/rrd_last.c index 85a725d5..d5267684 100644 --- a/src/rrd_last.c +++ b/src/rrd_last.c @@ -26,8 +26,9 @@ time_t rrd_last( while ((opt = optparse_long(&options, longopts, NULL)) != -1) { switch (opt) { case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup(options.optarg); if (opt_daemon == NULL) { @@ -38,7 +39,9 @@ time_t rrd_last( case '?': rrd_set_error("%s", options.errmsg); - if (opt_daemon) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return -1; } } /* while (opt) */ @@ -46,7 +49,9 @@ time_t rrd_last( if ((options.argc - options.optind) != 1) { rrd_set_error ("Usage: rrdtool %s [--daemon|-d ] ", options.argv[0]); - if (opt_daemon) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } return -1; } @@ -57,7 +62,9 @@ time_t rrd_last( else lastupdate = rrd_last_r(options.argv[options.optind]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (lastupdate); } diff --git a/src/rrd_lastupdate.c b/src/rrd_lastupdate.c index ddde70a6..5f7aefcc 100644 --- a/src/rrd_lastupdate.c +++ b/src/rrd_lastupdate.c @@ -29,8 +29,9 @@ int rrd_lastupdate (int argc, char **argv) while ((opt = optparse_long(&options, longopts, NULL)) != -1) { switch (opt) { case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup(options.optarg); if (opt_daemon == NULL) { @@ -41,7 +42,9 @@ int rrd_lastupdate (int argc, char **argv) case '?': rrd_set_error("%s", options.errmsg); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return -1; } } /* while (opt!=-1) */ @@ -49,12 +52,16 @@ int rrd_lastupdate (int argc, char **argv) if ((options.argc - options.optind) != 1) { rrd_set_error ("Usage: rrdtool %s [--daemon|-d ] ", options.argv[0]); - if (opt_daemon) free(opt_daemon); + if (opt_daemon != NULL) { + free(opt_daemon); + } return (-1); } status = rrdc_flush_if_daemon(opt_daemon, options.argv[options.optind]); - if (opt_daemon) free (opt_daemon); + if (opt_daemon != NULL) { + free (opt_daemon); + } if (status) return (-1); status = rrd_lastupdate_r(options.argv[options.optind], diff --git a/src/rrd_update.c b/src/rrd_update.c index 0fd85273..d4c696c5 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -692,7 +692,9 @@ int rrd_update( while ((opt = optparse_long(&options,longopts,NULL)) != -1) { switch (opt) { case 't': - if (tmplt) free(tmplt); + if (tmplt != NULL) { + free(tmplt); + } tmplt = strdup(options.optarg); break; @@ -701,8 +703,9 @@ int rrd_update( break; case 'd': - if (opt_daemon != NULL) + if (opt_daemon != NULL) { free (opt_daemon); + } opt_daemon = strdup (options.optarg); if (opt_daemon == NULL) { -- 2.47.2