[PATCH 3/3] amount_selected should never be decremented if already 0

me at bearsh.org me at bearsh.org
Sat Dec 7 04:25:18 UTC 2013


From: Martin Gysel <me at bearsh.org>

this is probably more a workaround than a proper fix to a problem which
I think only happens if started with no dive loaded and then create one.
in that case, deselect_dive is called after saving the dive but probalby
before it was added to the dive list properly resulting in an underflow
of amount_selected.

Signed-off-by: Martin Gysel <me at bearsh.org>
---
 divelist.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/divelist.c b/divelist.c
index 36f43e4..18435ca 100644
--- a/divelist.c
+++ b/divelist.c
@@ -820,7 +820,8 @@ void deselect_dive(int idx)
 	struct dive *dive = get_dive(idx);
 	if (dive && dive->selected) {
 		dive->selected = 0;
-		amount_selected--;
+		if (amount_selected)
+			amount_selected--;
 		if (selected_dive == idx && amount_selected > 0) {
 			/* pick a different dive as selected */
 			while (--selected_dive >= 0) {
-- 
1.8.5.1



More information about the subsurface mailing list