[OSM-dev] libxml2 segfault parsing OSM data with C++, but not C

Jon Burgess jburgess777 at googlemail.com
Thu Feb 14 22:32:44 GMT 2008


On Thu, 2008-02-14 at 21:40 +0000, Nick Whitelegg wrote:
> Hello everyone,
> 
> Have written a test program to attempt to parse OSM data with libxml2 using 
> its SAX parser, as an initial step in bringing direct OSM support to Mapnik. 
> For some reason, it runs successfully if it's a C program (saved as .c and 
> compiled with gcc) but segfaults if C++ (saved as .cpp, compiled with g++)
> 
> The crash occurs in xmlSAXUserParseFile though can't get any more specific 
> information than that.
> 
> Anyone who has used libxml got any idea on this one?
> 
> My test program is at
> 
> http://www.free-map.org.uk/xmlparse.cpp
> 
> with the test OSM file at
> 
> http://www.free-map.org.uk/test.osm
> 
> Thanks,
> Nick

You need to zero the my_handler structure before you use it
e.g.

#include <string.h>
...
memset(&my_handler,0, sizeof(my_handler));

	Jon



> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev





More information about the dev mailing list