From 8a1839610458ea788304f700886d54af680d6e53 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 4 Oct 2018 11:48:40 +0200 Subject: [PATCH] Cleanup: don't access downloadTable directly in Uemis-downloader The Uemis downloader determines the dive-number to be downloaded by either checking the download-table [interrupted connection] or the global dive table [fresh download]. The downloadTable is passed in the device data structure, but in the function to determine the latest dive, the global downloadTable is accessed directly [thus supposing that this table was passed in device data]. Instead, use the table from device data to avoid funny surprises should we change to a non-global download table. Signed-off-by: Berthold Stoeger --- core/uemis-downloader.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c index b5969f2cc..129a48373 100644 --- a/core/uemis-downloader.c +++ b/core/uemis-downloader.c @@ -1029,12 +1029,11 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char * return true; } -static char *uemis_get_divenr(char *deviceidstr, int force) +static char *uemis_get_divenr(char *deviceidstr, struct dive_table *table, int force) { uint32_t deviceid, maxdiveid = 0; int i; char divenr[10]; - struct dive_table *table; deviceid = atoi(deviceidstr); mindiveid = 0xFFFFFFFF; @@ -1044,11 +1043,11 @@ static char *uemis_get_divenr(char *deviceidstr, int force) * already have. * * Also, if "force_download" is true, do this even if we - * don't have any dives (maxdiveid will remain zero) + * don't have any dives (maxdiveid will remain ~0). + * + * Otherwise, use the global dive table. */ - if (force || downloadTable.nr) - table = &downloadTable; - else + if (!force && !table->nr) table = &dive_table; for (i = 0; i < table->nr; i++) { @@ -1350,7 +1349,7 @@ const char *do_uemis_import(device_data_t *data) goto bail; param_buff[1] = "notempty"; - newmax = uemis_get_divenr(deviceid, force_download); + newmax = uemis_get_divenr(deviceid, data->download_table, force_download); if (verbose) fprintf(stderr, "Uemis downloader: start looking at dive nr %s\n", newmax);