Skip to content

Commit

Permalink
Fix for bug #538 Malformed line crashed delimited text provider.
Browse files Browse the repository at this point in the history
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 2d99590
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "qgsrect.h"
#include "qgis.h"
#include "qgsmessageviewer.h"
#include "qgslogger.h"

#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 2d99590

Please sign in to comment.