Don't use the result of unsupported libdivecomputer calls

We report a bug if this is not unsupported and not successful. And then use
the result. Hello? So if this is not supported, we still use the result?

Oops. This has been around for a long time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-01-09 11:01:06 -08:00
parent d45e870289
commit 037d1ceefa

View file

@ -439,14 +439,15 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dive->dc.deviceid = devdata->deviceid; dive->dc.deviceid = devdata->deviceid;
dive->dc.diveid = calculate_diveid(fingerprint, fsize); dive->dc.diveid = calculate_diveid(fingerprint, fsize);
tm.tm_year = dt.year; if (rc == DC_STATUS_SUCCESS) {
tm.tm_mon = dt.month - 1; tm.tm_year = dt.year;
tm.tm_mday = dt.day; tm.tm_mon = dt.month - 1;
tm.tm_hour = dt.hour; tm.tm_mday = dt.day;
tm.tm_min = dt.minute; tm.tm_hour = dt.hour;
tm.tm_sec = dt.second; tm.tm_min = dt.minute;
dive->when = dive->dc.when = utc_mktime(&tm); tm.tm_sec = dt.second;
dive->when = dive->dc.when = utc_mktime(&tm);
}
// Parse the divetime. // Parse the divetime.
dev_info(devdata, translate("gettextFromC", "Dive %d: %s"), import_dive_number, get_dive_date_c_string(dive->when)); dev_info(devdata, translate("gettextFromC", "Dive %d: %s"), import_dive_number, get_dive_date_c_string(dive->when));
unsigned int divetime = 0; unsigned int divetime = 0;
@ -455,7 +456,8 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dev_info(devdata, translate("gettextFromC", "Error parsing the divetime")); dev_info(devdata, translate("gettextFromC", "Error parsing the divetime"));
goto error_exit; goto error_exit;
} }
dive->dc.duration.seconds = divetime; if (rc == DC_STATUS_SUCCESS)
dive->dc.duration.seconds = divetime;
// Parse the maxdepth. // Parse the maxdepth.
double maxdepth = 0.0; double maxdepth = 0.0;
@ -464,7 +466,8 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dev_info(devdata, translate("gettextFromC", "Error parsing the maxdepth")); dev_info(devdata, translate("gettextFromC", "Error parsing the maxdepth"));
goto error_exit; goto error_exit;
} }
dive->dc.maxdepth.mm = rint(maxdepth * 1000); if (rc == DC_STATUS_SUCCESS)
dive->dc.maxdepth.mm = rint(maxdepth * 1000);
#if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN) #if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN)
// if this is defined then we have a fairly late version of libdivecomputer // if this is defined then we have a fairly late version of libdivecomputer
@ -482,15 +485,16 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dev_info(devdata, translate("gettextFromC", "Error parsing temperature")); dev_info(devdata, translate("gettextFromC", "Error parsing temperature"));
goto error_exit; goto error_exit;
} }
switch(i) { if (rc == DC_STATUS_SUCCESS)
case 0: switch(i) {
dive->dc.airtemp.mkelvin = C_to_mkelvin(temperature); case 0:
break; dive->dc.airtemp.mkelvin = C_to_mkelvin(temperature);
case 1: // we don't distinguish min and max water temp here, so take min if given, max otherwise break;
case 2: case 1: // we don't distinguish min and max water temp here, so take min if given, max otherwise
dive->dc.watertemp.mkelvin = C_to_mkelvin(temperature); case 2:
break; dive->dc.watertemp.mkelvin = C_to_mkelvin(temperature);
} break;
}
} }
#endif #endif
@ -513,7 +517,8 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dev_info(devdata, translate("gettextFromC", "Error obtaining water salinity")); dev_info(devdata, translate("gettextFromC", "Error obtaining water salinity"));
goto error_exit; goto error_exit;
} }
dive->dc.salinity = rint(salinity.density * 10.0); if (rc == DC_STATUS_SUCCESS)
dive->dc.salinity = rint(salinity.density * 10.0);
double surface_pressure = 0; double surface_pressure = 0;
rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure); rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure);
@ -521,7 +526,8 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dev_info(devdata, translate("gettextFromC", "Error obtaining surface pressure")); dev_info(devdata, translate("gettextFromC", "Error obtaining surface pressure"));
goto error_exit; goto error_exit;
} }
dive->dc.surface_pressure.mbar = rint(surface_pressure * 1000.0); if (rc == DC_STATUS_SUCCESS)
dive->dc.surface_pressure.mbar = rint(surface_pressure * 1000.0);
#endif #endif
#ifdef DC_FIELD_STRING #ifdef DC_FIELD_STRING
@ -545,16 +551,17 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dev_info(devdata, translate("gettextFromC", "Error obtaining divemode")); dev_info(devdata, translate("gettextFromC", "Error obtaining divemode"));
goto error_exit; goto error_exit;
} }
switch(divemode) { if (rc == DC_STATUS_SUCCESS)
case DC_DIVEMODE_FREEDIVE: switch(divemode) {
case DC_DIVEMODE_GAUGE: case DC_DIVEMODE_FREEDIVE:
case DC_DIVEMODE_OC: /* Open circuit */ case DC_DIVEMODE_GAUGE:
dive->dc.dctype = OC; case DC_DIVEMODE_OC: /* Open circuit */
break; dive->dc.dctype = OC;
case DC_DIVEMODE_CC: /* Closed circuit */ break;
dive->dc.dctype = CCR; case DC_DIVEMODE_CC: /* Closed circuit */
break; dive->dc.dctype = CCR;
} break;
}
#endif #endif
rc = parse_gasmixes(devdata, dive, parser, ngases, data); rc = parse_gasmixes(devdata, dive, parser, ngases, data);