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

Lubomir I. Ivanov neolit123 at gmail.com
Wed Nov 25 06:53:01 PST 2015


On 25 November 2015 at 07:26, K. "pestophagous" Heller
<pestophagous at gmail.com> wrote:
> 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;

currently add_single_dive() assumes a safe index.
i think that add_single_dive() should not be touched, but instead the
mobile app should be fixed (models bug?).

lubomir
--


More information about the subsurface mailing list