[gdal-dev] MEM Datasets

James Meyer jamesm at lantic.net
Tue Jul 13 09:59:58 EDT 2010


Ah yes that's it.

Thanks a lot!

On 7/13/2010 2:33 PM, Frank Warmerdam wrote:
> 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,


More information about the gdal-dev mailing list