From 379f6296117ea41896fcd49bb7b787775050c00b Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Sat, 14 Mar 2009 14:35:53 +0100 Subject: [PATCH] Don't crash when area type is unknown --- src/Prep/ShapeFile/shape-decode.cxx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Prep/ShapeFile/shape-decode.cxx b/src/Prep/ShapeFile/shape-decode.cxx index 3e2e780b..836ca335 100644 --- a/src/Prep/ShapeFile/shape-decode.cxx +++ b/src/Prep/ShapeFile/shape-decode.cxx @@ -200,8 +200,14 @@ string get_shapefile_type(DBFHandle& hDBF, int rec) { #endif - string area = DBFReadStringAttribute( hDBF, rec, area_column ); - string code = DBFReadStringAttribute( hDBF, rec, code_column ); + const char *v = DBFReadStringAttribute( hDBF, rec, area_column ); + if ( v == 0 ) + return ""; + string area = v; + string code; + v = DBFReadStringAttribute( hDBF, rec, code_column ); + if ( v != 0 ) + code = v; cout << "next record = " << code << endl; // strip leading spaces @@ -814,6 +820,11 @@ int main( int argc, char **argv ) { if ( force_area_type.length() == 0 ) { area = get_shapefile_type(hDBF, i); SG_LOG( SG_GENERAL, SG_DEBUG, " area type = " << area); + if ( area.empty() ) + { + area = "Default"; + SG_LOG( SG_GENERAL, SG_ALERT, "No area type specified" ); + } } else { area = force_area_type; }