From d712edcdc900d2258ceaf3ad6f055fae0ef6dd1b Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 3 May 2016 11:14:09 -0700 Subject: [PATCH] Stop using strdup for tile-join matching --- mbtiles.cpp | 2 +- mbtiles.hpp | 2 ++ tile-join.cpp | 42 +++++++++++++++--------------------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/mbtiles.cpp b/mbtiles.cpp index fecaafc..0884a1e 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -107,7 +107,7 @@ static void quote(std::string *buf, const char *s) { buf->append(tmp, strlen(tmp)); } -static void aprintf(std::string *buf, const char *format, ...) { +void aprintf(std::string *buf, const char *format, ...) { va_list ap; char *tmp; diff --git a/mbtiles.hpp b/mbtiles.hpp index 3a535b1..93d0462 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -12,3 +12,5 @@ void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector > &file_keys, int nlayers, int forcetable, const char *attribution); void mbtiles_close(sqlite3 *outdb, char **argv); + +void aprintf(std::string *buf, const char *format, ...); diff --git a/tile-join.cpp b/tile-join.cpp index 64ed4c7..50f0673 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -65,40 +65,30 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector= 0) { - type = VT_NUMBER; - } + aprintf(&value, "%lld", (long long) val.numeric_value.int_value); + type = VT_NUMBER; } else if (val.type == mvt_double) { - if (asprintf(&value, "%g", val.numeric_value.double_value) >= 0) { - type = VT_NUMBER; - } + aprintf(&value, "%g", val.numeric_value.double_value); + type = VT_NUMBER; } else if (val.type == mvt_float) { - if (asprintf(&value, "%g", val.numeric_value.float_value) >= 0) { - type = VT_NUMBER; - } + aprintf(&value, "%g", val.numeric_value.float_value); + type = VT_NUMBER; } else if (val.type == mvt_bool) { - if (asprintf(&value, "%s", val.numeric_value.bool_value ? "true" : "false") >= 0) { - type = VT_BOOLEAN; - } + aprintf(&value, "%s", val.numeric_value.bool_value ? "true" : "false"); + type = VT_BOOLEAN; } else if (val.type == mvt_sint) { - if (asprintf(&value, "%lld", (long long) val.numeric_value.sint_value) >= 0) { - type = VT_NUMBER; - } + aprintf(&value, "%lld", (long long) val.numeric_value.sint_value); + type = VT_NUMBER; } else if (val.type == mvt_uint) { - if (asprintf(&value, "%llu", (long long) val.numeric_value.uint_value) >= 0) { - type = VT_NUMBER; - } + aprintf(&value, "%llu", (long long) val.numeric_value.uint_value); + type = VT_NUMBER; } else { continue; } @@ -116,7 +106,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector 0 && strcmp(key, header[0].c_str()) == 0) { - std::map >::iterator ii = mapping.find(std::string(value)); + std::map >::iterator ii = mapping.find(value); if (ii != mapping.end()) { std::vector fields = ii->second; @@ -158,8 +148,6 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector