Opened 10 years ago

Closed 10 years ago

#3782 closed defect (fixed)

CSV driver reads empty lines at end of file

Reported by: andersmoe Owned by: warmerdam
Priority: normal Milestone: 1.7.3
Component: OGR_SF Version: 1.7.2
Severity: normal Keywords: csv, empty lines, features


The CSV driver will treat empty lines at the end of the file as features.

This pertains to trunk as of 7-JUNE-2010.


Change History (3)

comment:1 Changed 10 years ago by Even Rouault

Knowning if an empty line is at the end of the file is hard, so I'd just stop reading the file at the first empty line encountered. Are empty lines expected to be found at the middle of the file ?

Proposed patch :

Index: ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp
--- ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp	(révision 20820)
+++ ogr/ogrsf_frmts/csv/ogrcsvlayer.cpp	(copie de travail)
@@ -281,9 +281,11 @@
 /*      Read the CSV record.                                            */
 /* -------------------------------------------------------------------- */
     char **papszTokens = CSVReadParseLine2( fpCSV, chDelimiter );
-    if( papszTokens == NULL )
+    if( papszTokens == NULL || papszTokens[0] == NULL )
+    {
+        CSLDestroy(papszTokens);
         return NULL;
+    }
 /* -------------------------------------------------------------------- */
 /*      Create the OGR feature.                                         */

comment:2 Changed 10 years ago by warmerdam

I think it would be better to just skip completely empty lines.

comment:3 Changed 10 years ago by Even Rouault

Resolution: fixed
Status: newclosed

Yes, that's what also the option I considered first.

Done in trunk in r20822 and branches/1.7 in r20823

Note: See TracTickets for help on using tickets.