diff --git a/attribute.cpp b/attribute.cpp index e4deb932..71f0d1cd 100644 --- a/attribute.cpp +++ b/attribute.cpp @@ -55,8 +55,9 @@ void set_attribute_accum(std::unordered_map &attribut exit(EXIT_JSON); } - size_t i = 0; - for (const auto &e : o->entries()) { + for (size_t i = 0; i < o->entries().size(); i++) { + const auto &e = o->entries()[i]; + if (e.key->type != JSON_STRING) { fprintf(stderr, "%s: -E%s: key %zu not a string\n", *argv, arg, i); exit(EXIT_JSON); @@ -66,8 +67,7 @@ void set_attribute_accum(std::unordered_map &attribut exit(EXIT_JSON); } - set_attribute_accum(attribute_accum, e.key->string().c_str(), e.value->string().c_str()); - i++; + set_attribute_accum(attribute_accum, e.key->string(), e.value->string()); } return; diff --git a/geojson.cpp b/geojson.cpp index 8997c5a2..b445e299 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -188,7 +188,7 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom if (e.key->type == JSON_STRING) { serial_val sv = stringify_value(e.value.get(), sst->fname, sst->line, feature); - full_keys.emplace_back(key_pool.pool(e.key->string().c_str())); + full_keys.emplace_back(key_pool.pool(e.key->string())); values.push_back(std::move(sv)); } } @@ -238,6 +238,10 @@ struct json_serialize_action : json_feature_action { std::string layername; int add_feature(json_object *geometry, bool geometrycollection, json_object *properties, json_object *id, json_object *tippecanoe, json_object *feature) { + // This only ever receives json_read results from geojson-loop, whose + // parser is still attached. json_read_tree / json_disconnect clear + // every parser pointer, so a detached tree would null-deref here. + assert(geometry->parser != nullptr); sst->line = geometry->parser->line; if (geometrycollection) { int ret = 1; diff --git a/geojson.hpp b/geojson.hpp index 8c63318c..3d7b7d26 100644 --- a/geojson.hpp +++ b/geojson.hpp @@ -17,7 +17,7 @@ struct parse_json_args { struct serialization_state *sst; parse_json_args(json_pull_ptr jp1, int layer1, std::string *layername1, struct serialization_state *sst1) - : jp(jp1), layer(layer1), layername(layername1), sst(sst1) { + : jp(std::move(jp1)), layer(layer1), layername(layername1), sst(sst1) { } }; diff --git a/main.cpp b/main.cpp index b393d269..5b877d43 100644 --- a/main.cpp +++ b/main.cpp @@ -2896,8 +2896,9 @@ void set_attribute_value(const char *arg) { exit(EXIT_JSON); } - size_t i = 0; - for (const auto &e : o->entries()) { + for (size_t i = 0; i < o->entries().size(); i++) { + const auto &e = o->entries()[i]; + if (e.key->type != JSON_STRING) { fprintf(stderr, "%s: --set-attribute %s: key %zu not a string\n", *av, arg, i); exit(EXIT_JSON); @@ -2905,7 +2906,6 @@ void set_attribute_value(const char *arg) { serial_val val = stringify_value(e.value.get(), "json", 1, o.get()); set_attributes.emplace(e.key->string(), val); - i++; } return; diff --git a/tile-join.cpp b/tile-join.cpp index 57094a96..84666840 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -973,8 +973,9 @@ void handle_strategies(const unsigned char *s, std::vector *st) { for (size_t i = 0; i < o->array().size(); i++) { const json_object_ptr &h = o->array()[i]; if (h->type == JSON_HASH) { - size_t j = 0; - for (const auto &kv : h->entries()) { + for (size_t j = 0; j < h->entries().size(); j++) { + const auto &kv = h->entries()[j]; + if (kv.key->type != JSON_STRING) { fprintf(stderr, "Key %zu of %zu is not a string: %s\n", j, i, s); } else if (kv.value->type != JSON_NUMBER) { @@ -1005,7 +1006,6 @@ void handle_strategies(const unsigned char *s, std::vector *st) { (*st)[i].feature_count += kv.value->number(); } } - j++; } } else { fprintf(stderr, "Element %zu is not a hash: %s\n", i, s);