[Gdal-dev] GDALCreateReprojectionTransformer()

Sean Forde sforde at lizardtech.com
Fri Feb 10 17:43:05 EST 2006


I have run in to some run time issues that can be tracked back to a failure in GDALCreateReprojectionTransformer(). The code snippet as it stands is...

<snip>
    poForwardTransform = OGRCreateCoordinateTransformation(&oSrcSRS,&oDstSRS);

    if( poForwardTransform == NULL )
        // OGRCreateCoordinateTransformation() will report errors on its own.
        return NULL;

/* -------------------------------------------------------------------- */
/*      Create a structure to hold the transform info, and also         */
/*      build reverse transform.  We assume that if the forward         */
/*      transform can be created, then so can the reverse one.          */
/* -------------------------------------------------------------------- */
    GDALReprojectionTransformInfo *psInfo;

    psInfo = (GDALReprojectionTransformInfo *)
        CPLCalloc(sizeof(GDALReprojectionTransformInfo),1);

    psInfo->poForwardTransform = poForwardTransform;
    psInfo->poReverseTransform =
        OGRCreateCoordinateTransformation(&oDstSRS,&oSrcSRS);
</snip>

The problem is that psInfo->poReverseTransform is never checked. If OGRCreateCoordinateTransformation
failed and psInfo->poReverseTransform is NULL, then you will get a segfault later when you actually apply the reprojection. That is, it is assumed that psInfo->poReverseTransform is non-NULL.

To address this I would add the following lines:

<change>
    if ( psInfo->poReverseTransform == NULL )
    {
       delete psInfo->poForwardTransform;
       CPLFree(psInfo);
       return NULL;
    }
</change>

Doing so is consistent with the error handling for poForwardTransform a few lines previous. 

I am not sure of the process for submitting patches, so apologies in advance if I am using the wrong venue.

	-Sean

Sean Forde
Geospatial Engineering Manager
LizardTech, a Celartem Company
http://www.lizardtech.com
206-902-2874




More information about the Gdal-dev mailing list