From 3479ac3f8664679ac40a345904dff4554d93469d Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Mon, 6 Jun 2011 12:06:35 +0200 Subject: [PATCH] Make osmpbf-outline more robust Add -g header for debugging. Remove -O3 header because it led to a segfault on a corrupted PBF file in the fread() call. Strange! Check result of ParseFromArray functions. --- tools/Makefile | 2 +- tools/osmpbf-outline.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 25be30c..b9fc26b 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,6 +1,6 @@ CXX = g++ -CXXFLAGS = -O3 -I../include +CXXFLAGS = -g -I../include LDFLAGS = -L../src -lpthread -lz -lprotobuf-lite -losmpbf all: osmpbf-outline diff --git a/tools/osmpbf-outline.cpp b/tools/osmpbf-outline.cpp index 4fe50dc..edd6e2f 100644 --- a/tools/osmpbf-outline.cpp +++ b/tools/osmpbf-outline.cpp @@ -135,7 +135,8 @@ int main(int argc, char *argv[]) { err("unable to read blob-header from file"); // parse the blob-header from the read-buffer - blobheader.ParseFromArray(buffer, sz); + if(!blobheader.ParseFromArray(buffer, sz)) + err("unable to parse blob header"); // tell about the blob-header info("\nBlobHeader (%d bytes)", sz); @@ -158,7 +159,8 @@ int main(int argc, char *argv[]) { err("unable to read blob from file"); // parse the blob from the read-buffer - blob.ParseFromArray(buffer, sz); + if(!blob.ParseFromArray(buffer, sz)) + err("unable to parse blob"); // tell about the blob-header info("Blob (%d bytes)", sz); @@ -262,7 +264,8 @@ int main(int argc, char *argv[]) { info(" OSMHeader"); // parse the HeaderBlock from the blob - headerblock.ParseFromArray(unpack_buffer, sz); + if(!headerblock.ParseFromArray(unpack_buffer, sz)) + err("unable to parse header block"); // tell about the bbox if(headerblock.has_bbox()) { @@ -296,7 +299,8 @@ int main(int argc, char *argv[]) { info(" OSMData"); // parse the PrimitiveBlock from the blob - primblock.ParseFromArray(unpack_buffer, sz); + if(!primblock.ParseFromArray(unpack_buffer, sz)) + err("unable to parse primitive block"); // tell about the block's meta info debug(" granularity: %u", primblock.granularity());