diff options
author | Salvador Cuñat <salvador.cunat@gmail.com> | 2017-04-02 23:30:24 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-04-04 10:54:55 -0700 |
commit | 4864ea56cbaa694ed237e854de2cfa1407fc18c4 (patch) | |
tree | 93c728a7726c9225865614d20d1aface021a9a4a /smtk-import | |
parent | 8c94fa2676dad64ae2a45329cfcdf8073760c6f5 (diff) | |
download | subsurface-4864ea56cbaa694ed237e854de2cfa1407fc18c4.tar.gz |
smtk-import Fix wreck data import
It was assumed that every data field in a wreck table was filled or
zeroed. This assumption is actually false, so this patch adds testing
for the existence of strings before working with them.
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Diffstat (limited to 'smtk-import')
-rw-r--r-- | smtk-import/smartrak.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index c7fadacf5..36eabed0b 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -266,24 +266,29 @@ static void smtk_wreck_site(MdbHandle *mdb, char *site_idx, struct dive_site *ds /* Begin parsing. Write strings to notes only if available.*/ while (mdb_fetch_row(table)) { if (!strcmp(col[1]->bind_ptr, site_idx)) { - tmp = copy_string(col[1]->bind_ptr); notes = smtk_concat_str(notes, "\n", translate("gettextFromC", "Wreck Data")); for (i = 3; i < 16; i++) { switch (i) { case 3: case 4: - if (memcmp(col[i]->bind_ptr, "\0", 1)) - notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], strtok(copy_string(col[i]->bind_ptr), " ")); + tmp = copy_string(col[i]->bind_ptr); + if (tmp) + notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], strtok(tmp , " ")); + free(tmp); break; case 5: - if (strcmp(rindex(copy_string(col[i]->bind_ptr), ' '), "\0")) - notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], rindex(col[i]->bind_ptr, ' ')); + tmp = copy_string(col[i]->bind_ptr); + if (tmp) + notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], rindex(tmp, ' ')); + free(tmp); break; case 6 ... 9: case 14: case 15: - if (memcmp(col[i]->bind_ptr, "\0", 1)) - notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], col[i]->bind_ptr); + tmp = copy_string(col[i]->bind_ptr); + if (tmp) + notes = smtk_concat_str(notes, "\n", "%s: %s", wreck_fields[i - 3], tmp); + free(tmp); break; default: d = lrintl(strtold(col[i]->bind_ptr, NULL)); @@ -300,7 +305,6 @@ static void smtk_wreck_site(MdbHandle *mdb, char *site_idx, struct dive_site *ds smtk_free(bound_values, table->num_cols); mdb_free_tabledef(table); free(notes); - free(tmp); } /* |