summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-04 12:02:54 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-04 12:05:28 +0100
commit76b31aa76ac3b29f3c41bc6ac72d6be524170ff3 (patch)
tree32c3443a5d352b878b0c7f5dc64d14af1769e71d /dive.c
parent769365b4db6b1beeeb1e86d106cf2ffead975747 (diff)
downloadsubsurface-76b31aa76ac3b29f3c41bc6ac72d6be524170ff3.tar.gz
Don't use the same variable name for loop and temp storage
Oops. Moving the check to the beginning of the function in order to avoid partial execution in commit 69036a1bb777 ("Avoid resource leak by bailing early") had a nasty side effect. Since Linus used 'i' both to hold the dive number and as a loop variable, by moving this to the top of the function the dive nr was overwritten which caused all kinds of problems. My bad - but of course you shouldn't mix loop variables with meaningful variables, either... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/dive.c b/dive.c
index 236485160..bbb1ff4ac 100644
--- a/dive.c
+++ b/dive.c
@@ -2851,13 +2851,13 @@ static struct dive *create_new_copy(struct dive *from)
*/
static int split_dive_at(struct dive *dive, int a, int b)
{
- int i, t;
+ int i, t, nr;
struct dive *d1, *d2;
struct divecomputer *dc1, *dc2;
struct event *event, **evp;
/* if we can't find the dive in the dive list, don't bother */
- if ((i = get_divenr(dive)) < 0)
+ if ((nr = get_divenr(dive)) < 0)
return 0;
/* We're not trying to be efficient here.. */
@@ -2920,8 +2920,8 @@ static int split_dive_at(struct dive *dive, int a, int b)
add_dive_to_trip(d2, dive->divetrip);
}
- delete_single_dive(i);
- add_single_dive(i, d1);
+ delete_single_dive(nr);
+ add_single_dive(nr, d1);
/*
* Was the dive numbered? If it was the last dive, then we'll
@@ -2929,12 +2929,12 @@ static int split_dive_at(struct dive *dive, int a, int b)
* Otherwise the tail is unnumbered.
*/
if (d2->number) {
- if (dive_table.nr == i+1)
+ if (dive_table.nr == nr + 1)
d2->number++;
else
d2->number = 0;
}
- add_single_dive(i+1, d2);
+ add_single_dive(nr + 1, d2);
mark_divelist_changed(true);