summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2015-02-01 13:45:07 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-01 07:06:12 -0800
commit2dc1a42b297eb49850767e71a644e5efc349b0c9 (patch)
treeab7cb7224edba1f967da8d1f76976e5d8837021f
parent1e45858ee6e40da932be301e39d3fced6b393490 (diff)
downloadsubsurface-2dc1a42b297eb49850767e71a644e5efc349b0c9.tar.gz
Fix crash if one selects incorrectly Seabear CSV
Fixes #814 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--file.c7
-rw-r--r--qt-ui/divelogimportdialog.cpp5
2 files changed, 10 insertions, 2 deletions
diff --git a/file.c b/file.c
index eacd8756a..e03edaf82 100644
--- a/file.c
+++ b/file.c
@@ -932,6 +932,13 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp
NL = "\r\n";
}
+ /*
+ * If file does not contain empty lines, it is not a valid
+ * Seabear CSV file.
+ */
+ if (!ptr)
+ return -1;
+
if (!ptr_old) {
while ((ptr = strstr(ptr, "\n\n")) != NULL) {
ptr_old = ptr;
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index c79b9df95..ca3a2bec5 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -526,7 +526,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
if (ui->knownImports->currentText() != "Manual import") {
for (int i = 0; i < fileNames.size(); ++i) {
if (ui->knownImports->currentText() == "Seabear CSV") {
- parse_seabear_csv_file(fileNames[i].toUtf8().data(),
+ if (parse_seabear_csv_file(fileNames[i].toUtf8().data(),
r.indexOf(tr("Sample time")),
r.indexOf(tr("Sample depth")),
r.indexOf(tr("Sample temperature")),
@@ -539,7 +539,8 @@ void DiveLogImportDialog::on_buttonBox_accepted()
ui->CSVSeparator->currentIndex(),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
ui->CSVUnits->currentIndex()
- );
+ ) < 0)
+ return;
// Seabear CSV stores NDL and TTS in Minutes, not seconds
struct dive *dive = dive_table.dives[dive_table.nr - 1];