diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-02-06 04:49:24 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-02-06 04:49:24 -0800 |
commit | 77ed1b682eba9a76fe452ebf1a8eaeb35902365b (patch) | |
tree | 72ba560fa71ce442f55c92d9cd9b25eeab1b74bd /tests | |
parent | 4c74b15e2fd4c70298f8405e1e22d52e07be45c4 (diff) | |
download | subsurface-77ed1b682eba9a76fe452ebf1a8eaeb35902365b.tar.gz |
TestParse: prevent crashes
Two CSV imports are failing right now; we shouldn't access uninitialized
memory when that happens.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testparse.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 0fa4eb8a2..9d44f6604 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -202,9 +202,11 @@ void TestParse::testParseHUDC() * CSV import uses time and date stamps relative to current * time, thus we need to use a static (random) timestamp */ - struct dive *dive = dive_table.dives[dive_table.nr - 1]; - dive->when = 1255152761; - dive->dc.when = 1255152761; + if (dive_table.nr > 0) { + struct dive *dive = dive_table.dives[dive_table.nr - 1]; + dive->when = 1255152761; + dive->dc.when = 1255152761; + } } void TestParse::testParseCompareHUDCOutput() @@ -342,14 +344,17 @@ void TestParse::testParseNewFormat() QCOMPARE(parse_seabear_csv_file(file.toUtf8().data(), params, pnr - 1, "csv"), 0); + QCOMPARE(dive_table.nr, 1); /* * Set artificial but static dive times so the result * can be compared to saved one. */ - dive = dive_table.dives[dive_table.nr - 1]; - dive->when = 1255152761 + 7200 * i; - dive->dc.when = 1255152761 + 7200 * i; + if (dive_table.nr > 0) { + dive = dive_table.dives[dive_table.nr - 1]; + dive->when = 1255152761 + 7200 * i; + dive->dc.when = 1255152761 + 7200 * i; + } } fprintf(stderr, "number of dives %d \n", dive_table.nr); |