[PATCH] Crash fix in add_single_dive. No writing to dive_table.dives[-1]

K. "pestophagous" Heller pestophagous at gmail.com
Tue Nov 24 21:26:00 PST 2015


Signed-off-by: K. Heller <pestophagous at gmail.com>
---

add_single_dive is called with idx = -1 in the mobile app.
Then a crash can happen afterward in several places 
depending on whether the timer first triggers the QMLProfile
to repaint or whether QtQuick tries further interactions 
with the DiveListModel.

to reproduce: launch with an empty dive list (such as
what happens if you have no cloud account and no dives yet)
and then choose 'Add Dive'.

i guess that 'Add Dive' is not necessarily supposed to be
working in the mobile app yet, but this crash fix seems
useful regardless.


 subsurface-core/divelist.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/subsurface-core/divelist.c b/subsurface-core/divelist.c
index a14fabf..a2e94c0 100644
--- a/subsurface-core/divelist.c
+++ b/subsurface-core/divelist.c
@@ -790,6 +790,9 @@ void add_single_dive(int idx, struct dive *dive)
 	dive_table.nr++;
 	if (dive->selected)
 		amount_selected++;
+	if (idx < 0)
+		// convert an idx of -1 so we do insert-at-end:
+		idx = dive_table.nr - 1;
 	for (i = idx; i < dive_table.nr; i++) {
 		struct dive *tmp = dive_table.dives[i];
 		dive_table.dives[i] = dive;
-- 
2.5.0



More information about the subsurface mailing list