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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-10-04 11:48:40 +02:00 committed by Dirk Hohndel
parent 5a78730561
commit 8a18396104

View file

@ -1029,12 +1029,11 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
return true; 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; uint32_t deviceid, maxdiveid = 0;
int i; int i;
char divenr[10]; char divenr[10];
struct dive_table *table;
deviceid = atoi(deviceidstr); deviceid = atoi(deviceidstr);
mindiveid = 0xFFFFFFFF; mindiveid = 0xFFFFFFFF;
@ -1044,11 +1043,11 @@ static char *uemis_get_divenr(char *deviceidstr, int force)
* already have. * already have.
* *
* Also, if "force_download" is true, do this even if we * 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) if (!force && !table->nr)
table = &downloadTable;
else
table = &dive_table; table = &dive_table;
for (i = 0; i < table->nr; i++) { for (i = 0; i < table->nr; i++) {
@ -1350,7 +1349,7 @@ const char *do_uemis_import(device_data_t *data)
goto bail; goto bail;
param_buff[1] = "notempty"; param_buff[1] = "notempty";
newmax = uemis_get_divenr(deviceid, force_download); newmax = uemis_get_divenr(deviceid, data->download_table, force_download);
if (verbose) if (verbose)
fprintf(stderr, "Uemis downloader: start looking at dive nr %s\n", newmax); fprintf(stderr, "Uemis downloader: start looking at dive nr %s\n", newmax);