[gdal-dev] MEM Datasets
Frank Warmerdam
warmerdam at pobox.com
Tue Jul 13 08:33:49 EDT 2010
James Meyer wrote:
> Hi
>
> Actually I did call it.
> Sorry I just didn't include it in the code because it was much earlier
> in the program.
>
> However after some playing around, it seems that the error only occurs
> IF I did a write to the MEM dataset. (Although it occurs WHEN I close it).
>
> The code I am using to test is below line-for-line exact. I basically
> read from an existing dataset (known to be GDT_Byte) into the in-memory
> dataset.
>
> It seems like some sort of buffer overflow, because if I delete the last
> two lines (that frees the buffers) I get a long "stack smash detected"
> printout in stead of a segmenation fault.
>
> Can you see anything I am doing wrong?
...
>> void* data = malloc(datasize);
>> sprintf(filename,
>> "MEM:::DATAPOINTER=%p,PIXELS=%d,LINES=%d,BANDS=%d,DATATYPE=%s",
>> &data, 100, 100, 1, GDALGetDataTypeName(GDT_Byte));
James,
In the sprintf() you should be passing "data" instead of "&data". Currently
you are passing the pointer to the pointer "data" on the stack which is only
4-8 bytes long and that is being used, and written past, blowing the stack.
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