Skip to content
Permalink
Browse files
Fix for bug #538 Malformed line crashed delimited text provider.
git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6511 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Feb 3, 2007
1 parent 6f00cfb commit 2d99590ba5322bef70bd96fcccbf3744930768ba
Showing with 19 additions and 4 deletions.
  1. +19 −4 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
@@ -39,6 +39,7 @@
#include "qgsrect.h"
#include "qgis.h"
#include "qgsmessageviewer.h"
#include "qgslogger.h"

#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
@@ -178,6 +179,12 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString const &uri)
// split the line on the delimiter
QStringList parts =
QStringList::split(mDelimiter, line, true);

// Skip malformed lines silently. Report line number with getNextFeature()
if ( (parts.size() <= fieldPositions[mXField]) || (parts.size() <= fieldPositions[mYField]) )
{
continue;
}
//if(parts.size() == attributeFields.size())
//{
// // we can populate attributes if required
@@ -356,24 +363,32 @@ QgsDelimitedTextProvider::getNextFeature_( QgsFeature & feature,
feature.setValid( false );
while ( ! mStream->atEnd() )
{
double x = 0.0;
double y = 0.0;
QString line = mStream->readLine(); // Default local 8 bit encoding
// lex the tokens from the current data line
QStringList tokens = QStringList::split(mDelimiter, line, true);

bool xOk = false;
bool yOk = false;

int xFieldPos = fieldPositions[mXField];
int yFieldPos = fieldPositions[mYField];
// Skip indexing malformed lines.
if ( ! ((tokens.size() <= fieldPositions[mXField]) || (tokens.size() <= fieldPositions[mXField])) )
{

int xFieldPos = fieldPositions[mXField];
int yFieldPos = fieldPositions[mYField];

double x = tokens[xFieldPos].toDouble( &xOk );
double y = tokens[yFieldPos].toDouble( &yOk );
x = tokens[xFieldPos].toDouble( &xOk );
y = tokens[yFieldPos].toDouble( &yOk );

}
if (! (xOk && yOk))
{
// Accumulate any lines that weren't ok, to report on them
// later, and look at the next line in the file, but only if
// we need to.
QgsDebugMsg("Malformed line : " + line);
if (mShowInvalidLines)
mInvalidLines << line;

0 comments on commit 2d99590

Please sign in to comment.