[gdal-dev] regarding GDALDriver::Create

Frank Warmerdam warmerdam at pobox.com
Fri Aug 14 08:01:32 EDT 2009


On Fri, Aug 14, 2009 at 2:59 AM, Srikanth<srikanth1947 at gmail.com> wrote:
> Dear All,
>
> I am reading and writing raster images using GDAL. Below is the code which I
> am using for writing a raster.
> At times the code is working fine. But many a time , it is getting crashed
> in the GetRasterBand. I have debugged the code several times and the
> variables passed seems to be perfect. Any help in this is regard would be
> appreciated.
...
>    poDataset=NULL;
>    poDataset = poDriver->Create(filename , width , height , numOfbands
> ,(GDALDataType)datatype,NULL);
>
>    for(int i=0 ; i < numOfbands ; i++)
>      {
>              poBand[i] = poDataset->GetRasterBand(i+1);
>       }

Hi,

I didn't see any showstopper problems in your code.  But
the above code is not safe if the dataset creation fails.
If the dataset creation fails, a null pointer will be returned
and GetRasterBand() will fail - possibly crashing.

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 Programmer for Rent


More information about the gdal-dev mailing list