From: Sami Kerola Date: Sat, 22 Jan 2011 11:35:18 +0000 (+0100) Subject: Arithmetic comparisons to be same way around X-Git-Tag: v2.14~16 X-Git-Url: http://git.asbjorn.biz/?p=debian%2Fdhcpd-pools.git;a=commitdiff_plain;h=ee35f8bb1f94b177675ab84b963a0fe61cd201eb Arithmetic comparisons to be same way around In writing arithmetic comparisons, use "<" and "<=" rather than ">" and ">=". For some justification, read this: http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126 Signed-off-by: Sami Kerola --- diff --git a/src/analyze.c b/src/analyze.c index 7a31699..c46d595 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -61,7 +61,7 @@ int prepare_data(void) &rangecomp); /* Sort backups */ - if (num_backups > 0) { + if (0 < num_backups) { qsort(backups, (size_t) num_backups, sizeof(long int), &intcomp); } @@ -81,9 +81,9 @@ int do_counting(void) /* Walk through ranges */ for (k = 0; k < num_ranges; k++) { /* Count IPs in use */ - for (; range_p->last_ip > leases[i] + for (; leases[i] < range_p->last_ip && (unsigned long) i < num_leases; i++) { - if (range_p->first_ip > leases[i]) { + if (leases[i] < range_p->first_ip) { continue; } /* IP with in range */ @@ -94,9 +94,9 @@ int do_counting(void) } /* Count touched IPs */ - for (; range_p->last_ip > touches[j] + for (; touches[j] < range_p->last_ip && (unsigned long) j < num_touches; j++) { - if (range_p->first_ip > touches[j]) { + if (touches[j] < range_p->first_ip) { continue; } /* IP with in range */ @@ -107,10 +107,10 @@ int do_counting(void) } /* Count backup IPs */ - if (num_backups > 0) { - for (; range_p->last_ip > backups[m] + if (0 < num_backups) { + for (; backups[m] < range_p->last_ip && (unsigned long) m < num_touches; m++) { - if (range_p->first_ip > touches[m]) { + if (touches[m] < range_p->first_ip) { continue; } /* IP with in range */ diff --git a/src/dhcpd-pools.c b/src/dhcpd-pools.c index 717743d..78a6ce0 100644 --- a/src/dhcpd-pools.c +++ b/src/dhcpd-pools.c @@ -140,7 +140,7 @@ int main(int argc, char **argv) /* Output sorting option */ if (optarg != NULL) { sorts = strlen(optarg); - if (sorts > 5) { + if (5 < sorts) { eprintf ("main: only 5 first sort orders will be used"); strncpy(config.sort, optarg, diff --git a/src/getdata.c b/src/getdata.c index 0356649..2fc1f5f 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2006- Sami Kerola < > +** Copyright (C) 2006- Sami Kerola ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -146,9 +146,9 @@ int parse_leases(void) }; } - if ((num_leases > leasesmallocsize) || - (num_touches > touchesmallocsize) || - (num_backups > backupsmallocsize)) { + if ((leasesmallocsize < num_leases) || + (touchesmallocsize < num_touches) || + (backupsmallocsize < num_backups)) { printf("WARNING: running out of memory\n"); printf("\tlease/touch/backup = %lu/%lu/%lu\n", leasesmallocsize, touchesmallocsize, @@ -350,7 +350,7 @@ char *parse_config(int is_include, char *config_file, i++; /* Long word which is almost causing overflow. Not any of words * this program is looking for are this long. */ - if (i > MAXLEN) { + if (MAXLEN < i) { newclause = false; i = 0; continue; @@ -414,7 +414,7 @@ char *parse_config(int is_include, char *config_file, range_p->backups = 0; range_p->shared_net = shared_p; num_ranges++; - if (num_ranges > RANGES) { + if (RANGES < num_ranges) { eprintf ("parse_config: Range space full! Increase RANGES and recompile."); exit(EXIT_FAILURE); @@ -435,7 +435,8 @@ char *parse_config(int is_include, char *config_file, /* printf ("include file: %s\n", word); */ argument = 0; next_free_shared_name = - parse_config(false, word, current_shared_name, + parse_config(false, word, + current_shared_name, next_free_shared_name, shared_p); newclause = true; diff --git a/src/output.c b/src/output.c index 22a67a4..613078d 100644 --- a/src/output.c +++ b/src/output.c @@ -54,7 +54,7 @@ int output_txt(void) fprintf (outfile, "shared net name first ip last ip max cur percent touch t+c t+c perc"); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, " bu bu perc"); } fprintf(outfile, "\n"); @@ -85,7 +85,7 @@ int output_txt(void) range_p->count)) / (range_p->last_ip - range_p->first_ip - 1)); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, "%7lu %8.3f", range_p->backups, (float) (100 * range_p->backups) / @@ -104,7 +104,7 @@ int output_txt(void) fprintf(outfile, "Shared networks:\n"); fprintf(outfile, "name max cur percent touch t+c t+c perc"); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, " bu bu perc"); } fprintf(outfile, "\n"); @@ -123,7 +123,7 @@ int output_txt(void) (shared_p->touched + shared_p->used)) / shared_p->available); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, "%7lu %8.3f", shared_p->backups, (float) (100 * shared_p->backups) / @@ -142,7 +142,7 @@ int output_txt(void) fprintf(outfile, "name max cur percent touch t+c t+c perc"); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, " bu bu perc"); } fprintf(outfile, "\n"); @@ -161,7 +161,7 @@ int output_txt(void) shared_networks->used)) / shared_networks->available); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, "%7lu %8.3f", shared_networks->backups, (float) (100 * shared_networks->backups) / @@ -451,7 +451,7 @@ int output_html(void) output_line(outfile, "th", "ralign", "touch"); output_line(outfile, "th", "ralign", "t+c"); output_line(outfile, "th", "ralign", "t+c perc"); - if (num_backups > 0) { + if (0 < num_backups) { output_line(outfile, "th", "ralign", "bu"); output_line(outfile, "th", "ralign", "bu perc"); } @@ -491,7 +491,7 @@ int output_html(void) range_p->count)) / (range_p->last_ip - range_p->first_ip - 1)); - if (num_backups > 0) { + if (0 < num_backups) { output_long(outfile, "td", range_p->backups); output_float(outfile, "td", @@ -517,7 +517,7 @@ int output_html(void) output_line(outfile, "th", "ralign", "touch"); output_line(outfile, "th", "ralign", "t+c"); output_line(outfile, "th", "ralign", "t+c perc"); - if (num_backups > 0) { + if (0 < num_backups) { output_line(outfile, "th", "ralign", "bu"); output_line(outfile, "th", "ralign", "bu perc"); } @@ -542,7 +542,7 @@ int output_html(void) (shared_p->touched + shared_p->used)) / shared_p->available); - if (num_backups > 0) { + if (0 < num_backups) { output_long(outfile, "td", shared_p->backups); output_float(outfile, "td", @@ -565,7 +565,7 @@ int output_html(void) output_line(outfile, "th", "ralign", "touch"); output_line(outfile, "th", "ralign", "t+c"); output_line(outfile, "th", "ralign", "t+c perc"); - if (num_backups > 0) { + if (0 < num_backups) { output_line(outfile, "th", "ralign", "bu"); output_line(outfile, "th", "ralign", "bu perc"); } @@ -590,7 +590,7 @@ int output_html(void) (shared_networks->touched + shared_networks->used)) / shared_networks->available); - if (num_backups > 0) { + if (0 < num_backups) { output_long(outfile, "td", shared_networks->backups); output_float(outfile, "td", @@ -645,7 +645,7 @@ int output_csv(void) fprintf (outfile, "\"shared net name\",\"first ip\",\"last ip\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\""); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, ",\"bu\",\"bu perc\""); } fprintf(outfile, "\n"); @@ -677,7 +677,7 @@ int output_csv(void) range_p->count)) / (range_p->last_ip - range_p->first_ip - 1)); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, ",\"%lu\",\"%.3f\"", range_p->backups, (float) (100 * range_p->backups) / @@ -695,7 +695,7 @@ int output_csv(void) fprintf(outfile, "\"Shared networks:\"\n"); fprintf(outfile, "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\""); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, ",\"bu\",\"bu perc\""); } fprintf(outfile, "\n"); @@ -715,7 +715,7 @@ int output_csv(void) (shared_p->touched + shared_p->used)) / shared_p->available); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, ",\"%lu\",\"%.3f\"", shared_p->backups, (float) (100 * shared_p->backups) / @@ -732,7 +732,7 @@ int output_csv(void) fprintf(outfile, "\"Sum of all ranges:\"\n"); fprintf(outfile, "\"name\",\"max\",\"cur\",\"percent\",\"touch\",\"t+c\",\"t+c perc\""); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, ",\"bu\",\"bu perc\""); } fprintf(outfile, "\n"); @@ -751,7 +751,7 @@ int output_csv(void) (shared_networks->touched + shared_networks->used)) / shared_networks->available); - if (num_backups > 0) { + if (0 < num_backups) { fprintf(outfile, "%7lu %8.3f", shared_networks->backups, (float) (100 * shared_networks->backups) / diff --git a/src/sort.c b/src/sort.c index 6c5ae58..ff6db69 100644 --- a/src/sort.c +++ b/src/sort.c @@ -135,7 +135,7 @@ int get_order(struct range_t *left, struct range_t *right) ret = strcmp(left->shared_net->name, right->shared_net->name); - if (ret > 0) { + if (0 < ret) { return (0); } else if (ret < 0) { return (1); @@ -170,7 +170,7 @@ void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp) if (size < MIN_MERGE_SIZE) { for (left = 0; left < size; left++) { hold = *(orig + left); - for (right = left - 1; right >= 0; right--) { + for (right = left - 1; 0 <= right; right--) { if (get_order((orig + right), &hold)) { break; }