From 4864ea56cbaa694ed237e854de2cfa1407fc18c4 Mon Sep 17 00:00:00 2001 From: Salvador Cuñat Date: Sun, 2 Apr 2017 23:30:24 +0200 Subject: smtk-import Fix wreck data import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- smtk-import/smartrak.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'smtk-import') 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); } /* -- cgit v1.2.3-70-g09d2