Opened 14 years ago

Closed 14 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
Cc:

Description

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

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

Anders

Change History (3)

comment:1 by Even Rouault, 14 years ago

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 by warmerdam, 14 years ago

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

comment:3 by Even Rouault, 14 years ago

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.