summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-12-26 14:04:10 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-12-26 14:04:10 -0800
commit0e94c21a55f713af300ff0fbf59ddee9558c3a0c (patch)
treed2f2d088cbaa0d3b0f64c34e431aa13e7baedcce
parentefb2640fc76dbba120c026831e0887c608ed4c66 (diff)
downloadsubsurface-0e94c21a55f713af300ff0fbf59ddee9558c3a0c.tar.gz
Cleanup: prevent potential out of bounds write
Since we cannot store tanks / gases past MAX_CYLINDERS (currently 20), there is no point in analyzing those data. Coverity CID 208339 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/libdivecomputer.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 14fe42a6e..fde142e0d 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -115,7 +115,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
#endif
bool no_volume = true;
- for (i = 0; i < ngases || i < ntanks; i++) {
+ for (i = 0; i < MAX_CYLINDERS && (i < ngases || i < ntanks); i++) {
if (i < ngases) {
dc_gasmix_t gasmix = { 0 };
int o2, he;
@@ -124,10 +124,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED)
return rc;
- if (i >= MAX_CYLINDERS)
- continue;
-
- o2 = lrint(gasmix.oxygen * 1000);
+ o2 = lrint(gasmix.oxygen * 1000);
he = lrint(gasmix.helium * 1000);
/* Ignore bogus data - libdivecomputer does some crazy stuff */