@@ -443,7 +443,7 @@ macro_rules! impl_read_for_point_container_type {
443
443
let mut points: Vec <P > = vec![ ] ;
444
444
let size = try!( read_u32( raw, is_be) ) as usize ;
445
445
for _ in 0 ..size {
446
- points. push( P :: read_ewkb_body( raw, is_be, srid) . unwrap ( ) ) ;
446
+ points. push( P :: read_ewkb_body( raw, is_be, srid) ? ) ;
447
447
}
448
448
Ok ( $geotype:: <P > { points: points, srid: srid} )
449
449
}
@@ -464,7 +464,7 @@ macro_rules! impl_read_for_point_container_type {
464
464
let mut points: Vec <P > = vec![ ] ;
465
465
let size = try!( read_u32( raw, is_be) ) as usize ;
466
466
for _ in 0 ..size {
467
- points. push( P :: read_ewkb( raw) . unwrap ( ) ) ;
467
+ points. push( P :: read_ewkb( raw) ? ) ;
468
468
}
469
469
Ok ( $geotype:: <P > { points: points, srid: srid} )
470
470
}
@@ -487,7 +487,7 @@ macro_rules! impl_read_for_geometry_container_type {
487
487
let mut $itemname: Vec <$itemtype<P >> = vec![ ] ;
488
488
let size = try!( read_u32( raw, is_be) ) as usize ;
489
489
for _ in 0 ..size {
490
- $itemname. push( $itemtype:: read_ewkb_body( raw, is_be, srid) . unwrap ( ) ) ;
490
+ $itemname. push( $itemtype:: read_ewkb_body( raw, is_be, srid) ? ) ;
491
491
}
492
492
Ok ( $geotype:: <P > { $itemname: $itemname, srid: srid} )
493
493
}
@@ -507,7 +507,7 @@ macro_rules! impl_read_for_geometry_container_type {
507
507
let mut $itemname: Vec <$itemtype<P >> = vec![ ] ;
508
508
let size = try!( read_u32( raw, is_be) ) as usize ;
509
509
for _ in 0 ..size {
510
- $itemname. push( $itemtype:: read_ewkb( raw) . unwrap ( ) ) ;
510
+ $itemname. push( $itemtype:: read_ewkb( raw) ? ) ;
511
511
}
512
512
Ok ( $geotype:: <P > { $itemname: $itemname, srid: srid} )
513
513
}
@@ -823,13 +823,13 @@ impl<P> EwkbRead for GeometryT<P>
823
823
}
824
824
825
825
let geom = match type_id & 0xff {
826
- 0x01 => GeometryT :: Point ( P :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
827
- 0x02 => GeometryT :: LineString ( LineStringT :: < P > :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
828
- 0x03 => GeometryT :: Polygon ( PolygonT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
829
- 0x04 => GeometryT :: MultiPoint ( MultiPointT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
830
- 0x05 => GeometryT :: MultiLineString ( MultiLineStringT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
831
- 0x06 => GeometryT :: MultiPolygon ( MultiPolygonT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
832
- 0x07 => GeometryT :: GeometryCollection ( GeometryCollectionT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
826
+ 0x01 => GeometryT :: Point ( P :: read_ewkb_body ( raw, is_be, srid) ? ) ,
827
+ 0x02 => GeometryT :: LineString ( LineStringT :: < P > :: read_ewkb_body ( raw, is_be, srid) ? ) ,
828
+ 0x03 => GeometryT :: Polygon ( PolygonT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
829
+ 0x04 => GeometryT :: MultiPoint ( MultiPointT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
830
+ 0x05 => GeometryT :: MultiLineString ( MultiLineStringT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
831
+ 0x06 => GeometryT :: MultiPolygon ( MultiPolygonT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
832
+ 0x07 => GeometryT :: GeometryCollection ( GeometryCollectionT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
833
833
_ => return Err ( Error :: Read ( format ! ( "Error reading generic geometry type - unsupported type id {}." , type_id) ) )
834
834
} ;
835
835
Ok ( geom)
@@ -877,13 +877,13 @@ impl<P> EwkbRead for GeometryCollectionT<P>
877
877
srid = Some ( try!( read_i32 ( raw, is_be) ) ) ;
878
878
}
879
879
let geom = match type_id & 0xff {
880
- 0x01 => GeometryT :: Point ( P :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
881
- 0x02 => GeometryT :: LineString ( LineStringT :: < P > :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
882
- 0x03 => GeometryT :: Polygon ( PolygonT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
883
- 0x04 => GeometryT :: MultiPoint ( MultiPointT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
884
- 0x05 => GeometryT :: MultiLineString ( MultiLineStringT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
885
- 0x06 => GeometryT :: MultiPolygon ( MultiPolygonT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
886
- 0x07 => GeometryT :: GeometryCollection ( GeometryCollectionT :: read_ewkb_body ( raw, is_be, srid) . unwrap ( ) ) ,
880
+ 0x01 => GeometryT :: Point ( P :: read_ewkb_body ( raw, is_be, srid) ? ) ,
881
+ 0x02 => GeometryT :: LineString ( LineStringT :: < P > :: read_ewkb_body ( raw, is_be, srid) ? ) ,
882
+ 0x03 => GeometryT :: Polygon ( PolygonT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
883
+ 0x04 => GeometryT :: MultiPoint ( MultiPointT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
884
+ 0x05 => GeometryT :: MultiLineString ( MultiLineStringT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
885
+ 0x06 => GeometryT :: MultiPolygon ( MultiPolygonT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
886
+ 0x07 => GeometryT :: GeometryCollection ( GeometryCollectionT :: read_ewkb_body ( raw, is_be, srid) ? ) ,
887
887
_ => return Err ( Error :: Read ( format ! ( "Error reading generic geometry type - unsupported type id {}." , type_id) ) )
888
888
} ;
889
889
ret. geometries . push ( geom) ;
@@ -1124,6 +1124,15 @@ fn test_geometry_read() {
1124
1124
assert_eq ! ( format!( "{:?}" , geom) , "GeometryCollection(GeometryCollectionT { geometries: [Point(Point { x: 10, y: 10, srid: None }), Point(Point { x: 30, y: 30, srid: None }), LineString(LineStringT { points: [Point { x: 15, y: 15, srid: None }, Point { x: 20, y: 20, srid: None }], srid: None })] })" ) ;
1125
1125
}
1126
1126
1127
+ #[ test]
1128
+ fn test_read_error ( ) {
1129
+ // SELECT 'LINESTRING (10 -20, 0 -0.5)'::geometry
1130
+ let ewkb = hex_to_vec ( "010200000002000000000000000000244000000000000034C00000000000000000000000000000E0BF" ) ;
1131
+ let poly = PolygonT :: < Point > :: read_ewkb ( & mut ewkb. as_slice ( ) ) ;
1132
+ assert ! ( poly. is_err( ) ) ;
1133
+ assert_eq ! ( format!( "{:?}" , poly) , "Err(Read(\" error while reading: Error { repr: Custom(Custom { kind: UnexpectedEof, error: StringError(\\ \" failed to fill whole buffer\\ \" ) }) }\" ))" ) ;
1134
+ }
1135
+
1127
1136
#[ test]
1128
1137
fn test_iterators ( ) {
1129
1138
// Iterator traits:
0 commit comments