From 0f1d2e4220df0dfb20ac9396c43d4f814202f2ea Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 3 May 2016 16:39:26 -0700 Subject: [PATCH] Fix additional g++ warnings --- geometry.cpp | 18 ++++++------------ main.cpp | 47 ++++++++++++++++++++++------------------------- tile-join.cpp | 2 +- tile.cpp | 2 +- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/geometry.cpp b/geometry.cpp index de5b0d8..c57feb4 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -204,9 +204,9 @@ drawvec shrink_lines(drawvec &geom, int z, int detail, int basezoom, long long * } #endif -double get_area(drawvec &geom, int i, int j) { +double get_area(drawvec &geom, size_t i, size_t j) { double area = 0; - for (unsigned k = i; k < j; k++) { + for (size_t k = i; k < j; k++) { area += (long double) geom[k].x * (long double) geom[i + ((k - i + 1) % (j - i))].y; area -= (long double) geom[k].y * (long double) geom[i + ((k - i + 1) % (j - i))].x; } @@ -214,10 +214,10 @@ double get_area(drawvec &geom, int i, int j) { return area; } -void reverse_ring(drawvec &geom, int start, int end) { +void reverse_ring(drawvec &geom, size_t start, size_t end) { drawvec tmp; - for (unsigned i = start; i < end; i++) { + for (size_t i = start; i < end; i++) { tmp.push_back(geom[i]); } @@ -375,8 +375,6 @@ static void decode_clipped(ClipperLib::PolyNode *t, drawvec &out) { static void dump(drawvec &geom) { ClipperLib::Clipper clipper(ClipperLib::ioStrictlySimple); - bool has_area = false; - for (size_t i = 0; i < geom.size(); i++) { if (geom[i].op == VT_MOVETO) { size_t j; @@ -386,11 +384,6 @@ static void dump(drawvec &geom) { } } - double area = get_area(geom, i, j); - if (area != 0) { - has_area = true; - } - ClipperLib::Path path; printf("{ ClipperLib::Path path; "); @@ -515,7 +508,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ static int pnpoly(drawvec &vert, size_t start, size_t nvert, long long testx, long long testy) { - int i, j, c = 0; + size_t i, j; + bool c = false; for (i = 0, j = nvert - 1; i < nvert; j = i++) { if (((vert[i + start].y > testy) != (vert[j + start].y > testy)) && (testx < (vert[j + start].x - vert[i + start].x) * (testy - vert[i + start].y) / (double) (vert[j + start].y - vert[i + start].y) + vert[i + start].x)) diff --git a/main.cpp b/main.cpp index efdaf31..d5d5fde 100644 --- a/main.cpp +++ b/main.cpp @@ -191,14 +191,14 @@ int indexcmp(const void *v1, const void *v2) { return 0; } -struct merge { +struct mergelist { long long start; long long end; - struct merge *next; + struct mergelist *next; }; -static void insert(struct merge *m, struct merge **head, unsigned char *map) { +static void insert(struct mergelist *m, struct mergelist **head, unsigned char *map) { while (*head != NULL && indexcmp(map + m->start, map + (*head)->start) > 0) { head = &((*head)->next); } @@ -207,9 +207,9 @@ static void insert(struct merge *m, struct merge **head, unsigned char *map) { *head = m; } -static void merge(struct merge *merges, int nmerges, unsigned char *map, FILE *f, int bytes, long long nrec, char *geom_map, FILE *geom_out, long long *geompos, long long *progress, long long *progress_max, long long *progress_reported) { +static void merge(struct mergelist *merges, int nmerges, unsigned char *map, FILE *f, int bytes, long long nrec, char *geom_map, FILE *geom_out, long long *geompos, long long *progress, long long *progress_max, long long *progress_reported) { int i; - struct merge *head = NULL; + struct mergelist *head = NULL; for (i = 0; i < nmerges; i++) { if (merges[i].start < merges[i].end) { @@ -232,7 +232,7 @@ static void merge(struct merge *merges, int nmerges, unsigned char *map, FILE *f fwrite_check(map + head->start, bytes, 1, f, "merge temporary"); head->start += bytes; - struct merge *m = head; + struct mergelist *m = head; head = m->next; m->next = NULL; @@ -246,7 +246,7 @@ struct sort_arg { int task; int cpus; long long indexpos; - struct merge *merges; + struct mergelist *merges; int indexfd; int nmerges; long long unit; @@ -556,8 +556,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split madvise(geommap, geomst.st_size, MADV_SEQUENTIAL); madvise(geommap, geomst.st_size, MADV_WILLNEED); - long long a; - for (a = 0; a < indexst.st_size / sizeof(struct index); a++) { + for (size_t a = 0; a < indexst.st_size / sizeof(struct index); a++) { struct index ix = indexmap[a]; unsigned long long which = (ix.index << prefix) >> (64 - splitbits); long long pos = sub_geompos[which]; @@ -629,7 +628,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split } if (indexst.st_size > 0) { - if (indexst.st_size > sizeof(struct index) && indexst.st_size + geomst.st_size < mem) { + if (indexst.st_size + geomst.st_size < mem) { long long indexpos = indexst.st_size; int bytes = sizeof(struct index); @@ -644,7 +643,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split unit = ((unit + page - 1) / page) * page; int nmerges = (indexpos + unit - 1) / unit; - struct merge merges[nmerges]; + struct mergelist merges[nmerges]; int a; for (a = 0; a < nmerges; a++) { @@ -723,8 +722,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split madvise(geommap, geomst.st_size, MADV_RANDOM); madvise(geommap, geomst.st_size, MADV_WILLNEED); - long long a; - for (a = 0; a < indexst.st_size / sizeof(struct index); a++) { + for (size_t a = 0; a < indexst.st_size / sizeof(struct index); a++) { struct index ix = indexmap[a]; long long pos = *geompos_out; @@ -964,7 +962,7 @@ int read_input(std::vector &sources, char *fname, const char *layername, initialized[i] = initial_x[i] = initial_y[i] = 0; } - int nlayers; + size_t nlayers; if (layername != NULL) { nlayers = 1; } else { @@ -974,7 +972,7 @@ int read_input(std::vector &sources, char *fname, const char *layername, } } - int nsources = sources.size(); + size_t nsources = sources.size(); if (nsources == 0) { nsources = 1; } @@ -982,8 +980,7 @@ int read_input(std::vector &sources, char *fname, const char *layername, std::vector > file_keys; long overall_offset = 0; - int source; - for (source = 0; source < nsources; source++) { + for (size_t source = 0; source < nsources; source++) { file_keys.push_back(std::set()); std::string reading; int fd; @@ -1178,17 +1175,17 @@ int read_input(std::vector &sources, char *fname, const char *layername, } std::vector layernames; - for (i = 0; i < nlayers; i++) { + for (size_t l = 0; l < nlayers; l++) { if (layername != NULL) { layernames.push_back(std::string(layername)); } else { const char *src; if (sources.size() < 1) { src = fname; - } else if (sources[i].layer.size() != 0) { - src = sources[i].layer.c_str(); + } else if (sources[l].layer.size() != 0) { + src = sources[l].layer.c_str(); } else { - src = sources[i].file.c_str(); + src = sources[l].file.c_str(); } // Find the last component of the pathname @@ -1213,15 +1210,15 @@ int read_input(std::vector &sources, char *fname, const char *layername, // Trim out characters that can't be part of selector std::string out; - for (cp = 0; cp < trunc.size(); cp++) { - if (isalpha(trunc[cp]) || isdigit(trunc[cp]) || trunc[cp] == '_') { - out.append(trunc, cp, 1); + for (size_t p = 0; p < trunc.size(); p++) { + if (isalpha(trunc[p]) || isdigit(trunc[p]) || trunc[p] == '_') { + out.append(trunc, p, 1); } } layernames.push_back(out); if (!quiet) { - fprintf(stderr, "For layer %d, using name \"%s\"\n", i, out.c_str()); + fprintf(stderr, "For layer %d, using name \"%s\"\n", (int) l, out.c_str()); } } } diff --git a/tile-join.cpp b/tile-join.cpp index e9f65f9..5f7a56e 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -62,7 +62,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector partials; std::vector > features; - for (size_t i = 0; i < nlayers; i++) { + for (int i = 0; i < nlayers; i++) { features.push_back(std::vector()); }