mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-22 04:18:01 +00:00
Stop using strdup for tile-join matching
This commit is contained in:
parent
271ec3d154
commit
d712edcdc9
@ -107,7 +107,7 @@ static void quote(std::string *buf, const char *s) {
|
|||||||
buf->append(tmp, strlen(tmp));
|
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;
|
va_list ap;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
|
@ -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<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution);
|
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution);
|
||||||
|
|
||||||
void mbtiles_close(sqlite3 *outdb, char **argv);
|
void mbtiles_close(sqlite3 *outdb, char **argv);
|
||||||
|
|
||||||
|
void aprintf(std::string *buf, const char *format, ...);
|
||||||
|
@ -65,40 +65,30 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector<std:
|
|||||||
for (int t = 0; t + 1 < feat.tags.size(); t += 2) {
|
for (int t = 0; t + 1 < feat.tags.size(); t += 2) {
|
||||||
const char *key = layer.keys[feat.tags[t]].c_str();
|
const char *key = layer.keys[feat.tags[t]].c_str();
|
||||||
mvt_value &val = layer.values[feat.tags[t + 1]];
|
mvt_value &val = layer.values[feat.tags[t + 1]];
|
||||||
char *value;
|
std::string value;
|
||||||
int type = -1;
|
int type = -1;
|
||||||
|
|
||||||
if (val.type == mvt_string) {
|
if (val.type == mvt_string) {
|
||||||
value = strdup(val.string_value.c_str());
|
value = val.string_value;
|
||||||
if (value == NULL) {
|
|
||||||
perror("Out of memory");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
type = VT_STRING;
|
type = VT_STRING;
|
||||||
} else if (val.type == mvt_int) {
|
} else if (val.type == mvt_int) {
|
||||||
if (asprintf(&value, "%lld", (long long) val.numeric_value.int_value) >= 0) {
|
aprintf(&value, "%lld", (long long) val.numeric_value.int_value);
|
||||||
type = VT_NUMBER;
|
type = VT_NUMBER;
|
||||||
}
|
|
||||||
} else if (val.type == mvt_double) {
|
} else if (val.type == mvt_double) {
|
||||||
if (asprintf(&value, "%g", val.numeric_value.double_value) >= 0) {
|
aprintf(&value, "%g", val.numeric_value.double_value);
|
||||||
type = VT_NUMBER;
|
type = VT_NUMBER;
|
||||||
}
|
|
||||||
} else if (val.type == mvt_float) {
|
} else if (val.type == mvt_float) {
|
||||||
if (asprintf(&value, "%g", val.numeric_value.float_value) >= 0) {
|
aprintf(&value, "%g", val.numeric_value.float_value);
|
||||||
type = VT_NUMBER;
|
type = VT_NUMBER;
|
||||||
}
|
|
||||||
} else if (val.type == mvt_bool) {
|
} else if (val.type == mvt_bool) {
|
||||||
if (asprintf(&value, "%s", val.numeric_value.bool_value ? "true" : "false") >= 0) {
|
aprintf(&value, "%s", val.numeric_value.bool_value ? "true" : "false");
|
||||||
type = VT_BOOLEAN;
|
type = VT_BOOLEAN;
|
||||||
}
|
|
||||||
} else if (val.type == mvt_sint) {
|
} else if (val.type == mvt_sint) {
|
||||||
if (asprintf(&value, "%lld", (long long) val.numeric_value.sint_value) >= 0) {
|
aprintf(&value, "%lld", (long long) val.numeric_value.sint_value);
|
||||||
type = VT_NUMBER;
|
type = VT_NUMBER;
|
||||||
}
|
|
||||||
} else if (val.type == mvt_uint) {
|
} else if (val.type == mvt_uint) {
|
||||||
if (asprintf(&value, "%llu", (long long) val.numeric_value.uint_value) >= 0) {
|
aprintf(&value, "%llu", (long long) val.numeric_value.uint_value);
|
||||||
type = VT_NUMBER;
|
type = VT_NUMBER;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -116,7 +106,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector<std:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) {
|
if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) {
|
||||||
std::map<std::string, std::vector<std::string> >::iterator ii = mapping.find(std::string(value));
|
std::map<std::string, std::vector<std::string> >::iterator ii = mapping.find(value);
|
||||||
|
|
||||||
if (ii != mapping.end()) {
|
if (ii != mapping.end()) {
|
||||||
std::vector<std::string> fields = ii->second;
|
std::vector<std::string> fields = ii->second;
|
||||||
@ -158,8 +148,6 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::vector<std:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matched || !ifmatched) {
|
if (matched || !ifmatched) {
|
||||||
|
Loading…
Reference in New Issue
Block a user