aboutsummaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-12-11 15:26:47 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-12-11 16:29:02 +0100
commitf09afad5a0515e2e40a91385d115840bc321697a (patch)
tree64ab3ba71a8320c0c59368764ca50ac468c94e64 /divelist.c
parentea895fbecc4b7aea0eacc9cb7ce3acece926343c (diff)
downloadsubsurface-f09afad5a0515e2e40a91385d115840bc321697a.tar.gz
divelist.c: Fix possible NULL pointer deref.
calculate_cns(): The check if prev_dive is NULL should be before calling prev_dive->when. Reported by the program cppcheck. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/divelist.c b/divelist.c
index c69a34dc5..0004832c6 100644
--- a/divelist.c
+++ b/divelist.c
@@ -266,10 +266,12 @@ static int calculate_cns(struct dive *dive)
divenr = get_divenr(dive);
if (divenr) {
prev_dive = get_dive(divenr -1 );
- endtime = prev_dive->when + prev_dive->duration.seconds;
- if (prev_dive && dive->when < (endtime + 3600 * 12)) {
- cns = calculate_cns(prev_dive);
- cns = cns * 1/pow(2, (dive->when - endtime) / (90.0 * 60.0));
+ if (prev_dive) {
+ endtime = prev_dive->when + prev_dive->duration.seconds;
+ if (dive->when < (endtime + 3600 * 12)) {
+ cns = calculate_cns(prev_dive);
+ cns = cns * 1/pow(2, (dive->when - endtime) / (90.0 * 60.0));
+ }
}
}
/* Caclulate the cns for each sample in this dive and sum them */