[geos-devel] segfault against 3.3.0 C++

Maxime van Noppen maxime at altribe.org
Mon Sep 12 03:39:47 EDT 2011


On 09/11/2011 12:39 AM, Matt Perry wrote:
> Beautiful. It compiles fine and no segfaults on our test cases. Still
> makes me nervous that this can happen anywhere in the code since the
> C++ API is a moving target - the long term solution is still a C API
> port but this fix buys some time. Thanks!
>
> +	Geometry* geos_geom = (Geometry*) poly->exportToGEOS();
> +	Polygon* geos_poly = dynamic_cast<Polygon*>( geos_geom );

We encountered this some time ago (the thread is in the geos-devel 
list). As strk said, now the whole geos hierarchy is virtual, therefore 
forbidding static_cast. So you can crawl your code base and replace all 
the casts.

By the way, using the C-style cast in C++ is really asking for trouble, 
use the appropriate cast between static_cast, dynamic_cast, 
reinterpret_cast or const_cast.

-- 
Maxime


More information about the geos-devel mailing list