Skip to content

Commit

Permalink
rev: throw exception if invalid wkb type
Browse files Browse the repository at this point in the history
changes per #522 (comment)

also modifies switch to return instead of assign to `g`.
  • Loading branch information
program-- authored and mattw-nws committed Jul 18, 2023
1 parent 2efe186 commit 724adeb
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/geopackage/wkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,25 @@ typename wkb::geometry wkb::read(const byte_vector& buffer)
uint32_t type;
utils::copy_from(buffer, index, type, order);

geometry g;
switch(type) {
case 1: g = read_point(buffer, index, order); break;
case 2: g = read_linestring(buffer, index, order); break;
case 3: g = read_polygon(buffer, index, order); break;
case 4: g = read_multipoint(buffer, index, order); break;
case 5: g = read_multilinestring(buffer, index, order); break;
case 6: g = read_multipolygon(buffer, index, order); break;
default: g = point_t{std::nan("0"), std::nan("0")}; break;
case 1:
return read_point(buffer, index, order);
case 2:
return read_linestring(buffer, index, order);
case 3:
return read_polygon(buffer, index, order);
case 4:
return read_multipoint(buffer, index, order);
case 5:
return read_multilinestring(buffer, index, order);
case 6:
return read_multipolygon(buffer, index, order);
default:
throw std::runtime_error(
"this reader only implements OGC geometry types 1-6, "
"but received type " + std::to_string(type)
);
}

return g;
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 724adeb

Please sign in to comment.