Opened 21 years ago

Last modified 21 years ago

#335 closed defect (fixed)

CR/LF problem with OGR GML driver on windows/dos

Reported by: rogerjames99@… Owned by: warmerdam
Priority: lowest Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc:

Description

The following code snippet from gmlreader.cpp (line 597) has a problem on 
windows. It's the old cr/lf thing.

    if( VSIFRead( pszWholeText, nLength, 1, fp ) != 1 )
    {
        VSIFree( pszWholeText );
        VSIFClose( fp );
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Read failed on %s.", pszFile );
        return FALSE;
    }

This will always fail on windos because the file has been opened in text mode 
and crlf translation is taking place. You have calculated nLength by using the 
position pointers, which give the length on disk including lf chars. VSIFRead 
calls fread which calculates its read length after the lf chars have been 
stripped. This means this piece of code always detects a failure and the reader 
goes on to create another gfs file, which it then fails to save because one 
already exists.

I cannot think of an easy clean fix for this one without prescanning the file. 
The dirty way is to ignore the test on windos systems.

Change History (1)

comment:1 by warmerdam, 21 years ago

Roger,

My simplistic fix is to just open the file in binary mode.  This patch has
been applied. 

Let me know if this does not resolve the problem. 


Note: See TracTickets for help on using tickets.