Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions include/osmium/builder/osm_object_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ namespace osmium {
if (value_length > osmium::max_osm_string_length) {
throw std::length_error{"OSM tag value is too long"};
}
add_size(append_with_zero(key, static_cast<osmium::memory::item_size_type>(key_length)));
add_size(append_with_zero(value, static_cast<osmium::memory::item_size_type>(value_length)));
const auto size = static_cast<osmium::memory::item_size_type>(key_length + value_length + 2);
unsigned char* target = reserve_space(size);
target = std::copy_n(reinterpret_cast<const unsigned char*>(key), key_length, target);
*target++ = '\0';
target = std::copy_n(reinterpret_cast<const unsigned char*>(value), value_length, target);
*target = '\0';
add_size(size);
}

/**
Expand All @@ -154,14 +159,7 @@ namespace osmium {
* @param value Tag value.
*/
void add_tag(const std::string_view& key, const std::string_view& value) {
if (key.size() > osmium::max_osm_string_length) {
throw std::length_error{"OSM tag key is too long"};
}
if (value.size() > osmium::max_osm_string_length) {
throw std::length_error{"OSM tag value is too long"};
}
add_size(append_with_zero(key.data(), static_cast<osmium::memory::item_size_type>(key.size())));
add_size(append_with_zero(value.data(), static_cast<osmium::memory::item_size_type>(value.size())));
add_tag(key.data(), key.size(), value.data(), value.size());
}

/**
Expand Down Expand Up @@ -495,6 +493,9 @@ namespace osmium {
const auto size_of_object = sizeof(T) + sizeof(string_size_type);
assert(cobject().user_size() == 1 && (size() <= size_of_object + osmium::memory::padded_length(1))
&& "set_user() must be called at most once and before any sub-builders");
if (length == 0) {
return static_cast<TDerived&>(*this);
}
constexpr const auto available_space = min_size_for_user - sizeof(string_size_type) - 1;
if (length > available_space) {
const auto space_needed = osmium::memory::padded_length(length - available_space);
Expand Down
18 changes: 13 additions & 5 deletions include/osmium/io/detail/pbf_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,18 +614,26 @@ namespace osmium {
}

void build_tag_list_from_dense_nodes(osmium::builder::NodeBuilder& builder, values_access_int32& tags) {
auto idx = tags.next_int32();
if (idx == 0) {
return;
}

osmium::builder::TagListBuilder tl_builder{builder};
while (!tags.empty()) {
const auto idx = tags.next_int32();
if (idx == 0) {
return;
}
while (true) {
const auto& k = m_stringtable.at(idx);
if (tags.empty()) {
throw osmium::pbf_error{"PBF format error"}; // this is against the spec, keys/vals must come in pairs
}
const auto& v = m_stringtable.at(tags.next_int32());
tl_builder.add_tag(k.first, k.second, v.first, v.second);
if (tags.empty()) {
return;
}
idx = tags.next_int32();
if (idx == 0) {
return;
}
}
}

Expand Down