[gdal-dev] Possible bug in OGRSpatialReference:: importFromWkt()

Martin Chapman chapmanm at pixia.com
Thu Jan 12 22:20:02 EST 2012


Ok, I'm cool with that, I just wanted to make sure it wasn't a bug.

Thanks for the quick response!

Best regards,

-----Original Message-----
From: fwarmerdam at gmail.com [mailto:fwarmerdam at gmail.com] On Behalf Of
Frank Warmerdam
Sent: Thursday, January 12, 2012 8:17 PM
To: Martin Chapman
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Possible bug in OGRSpatialReference::

On Thu, Jan 12, 2012 at 6:30 PM, Martin Chapman <chapmanm at pixia.com>
> Frank,
> I think there is a bug in OGRSpatialReference::importFromWkt().  I did
> the
> following:
> char* wkt = NULL;
> sourceSRS.exportToWkt(&wkt);
> targetSRS.importFromWkt(&wkt);
> CPLFree(wkt);
> It blows up on the CPLFree().  Why you might ask.  Because it looks
> like the
> importFromWkt() increments the pointer as it’s parsing it so by the
> time it returns the pointer you passed in no longer points to the
> beginning of the array of char* pointers. Instead, it points to the end
of the memory block.
> Shouldn’t you be assigning a temp pointer to the start of the array
> before you start parsing it?  If you made it a const char** parameter
> this wouldn’t happen.


The behavior is intentional though quite possibly ill advised.

The original intent was that the modified pointer after the import would
indicate what had not been consumed by the import parser.  But in practice
this has just make for a messy to use API and generally speaking callers
have to setup their own temporary pointer for the import.

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam,
warmerdam at pobox.com light and sound - activate the windows |
http://pobox.com/~warmerdam and watch the world go round - Rush    |
Geospatial Software Developer

More information about the gdal-dev mailing list