[Gdal-dev] Null-Pointer in GDALOpen?

Tom Kazimiers 2voodoo at gmx.de
Mon Oct 22 18:21:53 EDT 2007


Mateusz Loskot schrieb:
> Tom Kazimiers wrote:
>   
>> Mateusz Loskot schrieb:
>>     
>>> Tom Kazimiers wrote:
>>>       
>>>> thanks for the replys.
>>>> Sure I do test against null - the posted code was just an excerpt :) -
>>>> thanks anyway.
>>>> And yes, the crash occurs within GDALOpen() - I put a MessageBox before
>>>> and after GDALOpen() - only the first one appeared, than the crash.
>>>> The file handle explanation looked promising but before this line is
>>>> arrived I still can open files plus after a restart it also does not work.
>>>>         
>>> Tom,
>>>
>>> It sounds strange. Perhaps you could post complete snippet of code,
>>> then it will be easier to investigate it.
>>>       
>> Ok, here is a bigger part of it:
>>
>> bool CGDALContainer::AddFile(const wchar_t * w_pszFileName)
>> {   
>>    
>>     // Convert wchar_t to char
>>     const int newsize = wcslen(w_pszFileName);
>>     char    *pszFileName = (char *)malloc(newsize + 1);
>>     int count = wcstombs(pszFileName, w_pszFileName, newsize);
>>     
>
> Tom,
>
> wcstombs will work only for ASCII subset of characters.
> If w_pszFileName consists of non-ASCII characters, but some characters
> >from polish, french, czech languages, it will not translate the string
> properly. You need to use codepage aware function, like
> WideCharToMultiByte from Windows API.
>   

Ok - thank you - I'll do! I just remembered wrong, I thought wcstombs is
locale aware.
>   
>>     if (count == 0 || count != newsize) {
>>         FILE * pFile = _wfopen(L"PDAShpTool_ErrorLog.log",L"a");
>>         fwprintf(pFile, L"Error: The Filename \"%s\" could not be
>> converted to Const Char *!\n", w_pszFileName);
>>         fwprintf(pFile, L"       Charactos before: %d Converted items:
>> %d\n", newsize, count);
>>         fclose(pFile);
>>         return false;
>>     }
>>     pszFileName[newsize] = '\0'; // one never knows...
>>     GDALDataset  *poDataset = NULL;
>>    
>>     GDALAllRegister();
>>
>>     MessageBoxW(NULL, L"HA", L"DLL", MB_OK);
>>     poDataset = (GDALDataset *) GDALOpen( "\a.tif" /*pszFileName*/,
>> GA_ReadOnly );
>>     
>
> Replace \a.tif with \\a.tif
>
>   
Oops - Sorry - you are right. No wonder why I got this strange symbol.

>>>> The path "a.tif" is the full path of the file as this image is stored in
>>>> root directory of Windows CE 5.
>>>>         
>>> Do you mean that using file name only works like full path to root
>>> directory \, then it's wrong. It doesn't work this way under Windows CE.
>>>
>>> If you use only file name, it's assumed you open it from \My Documents,
>>> which is a default data location under Windows CE.
>>>       
>> Thanks for this hint - strange enough that it worked until yesterday
>> evening with only the filename for the root directory.
>> One more thing is that if I put "a.tif" in to open it crashes - if I put
>> "\a.tif" in it does not crash - it just returns NULL and I
>> can handle this (besides that the null return is strange, also). The
>> error returned by CPLGetLastError() is:
>> CPLError: `.tif' does not exist in the file system
>>     
>
> yes, because \a is escape sequence but not backslach + 'a' letter.
> Use \\a to get string like "\a"
>
>   
yes. sure.
>> This error was without convertig from wchar_t to char  - it was with
>> "\a.tif" inserted directly. It seems as if the const char * is not
>> received properly.
>>     
>
> Because you don't get what you expected as filename.
>
>   
>> Like I said, I can not really imagine that the problem is really
>> GDALOpen as it worked until yesterday and I did not change the dll.
>> But the crash occurs there.
>>     
>
> Perhaps you accidentally removed slash from correct sequence of \\
>
>   
>>>> The last thing I tryed was to put "GDALAllRegister();" right befor
>>>> GDALOpen() - before this I did it in completely different function,
>>>> which I think, should work, too.
>>>> But also this change did it not...
>>>>         
>>> Another thing I'd suggest to check is to see if you have built GDAL with
>>>  GTiff driver, means check if the GTiff driver is properly registered
>>> and available, in run-time.
>>>       
>> At least returns
>> "GetGDALDriverManager()->GetDriverByName("GTiff")->GetDescription()":
>> GTiff
>>
>> So I think it gets registered properly.
>>     
>
> Yes, it's OK.
>
> Cheers
>   
I also did not pass any wide-char characters to GDAL - always char.

I looked a bit more through the classes - but I can not find any error -
The last thing was the "TIFF*
TIFFClientOpen()" Function in tif_open.c
But really can't image that this is the problem.
More and more I doubt that the problem is in GDAL - there must be
something on my side - I tryed also several versions
of my project earlier and it does not work.
The PDA condifuration can't it also be as I testet it in emulator and in
real PDA.

strange...

Bye & thanks
Tom



More information about the Gdal-dev mailing list