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

Lubomir I. Ivanov neolit123 at gmail.com
Wed Nov 25 10:54:44 PST 2015


On 25 November 2015 at 20:48, K. "pestophagous" Heller
<pestophagous at gmail.com> wrote:
> On Wed, Nov 25, 2015 at 10:38 AM, Lubomir I. Ivanov <neolit123 at gmail.com> wrote:
>>> +       if (idx < 0)
>>> +               // convert an idx of -1 so we do insert-at-end:
>>> +               idx = dive_table.nr - 1;
>>
>> forgot to mention that in the above assignment dive_table.nr needs to
>> be > 0, otherwise a negative index will remain.
>>
>
> unless other code misuses dive_table, then i think we need not worry.
> yet. (but i do love adding assertions...)
>
> note that this line happens first:
>   dive_table.nr++
>
> so by the time the new code computes (dive_table.nr - 1),
> dive_table.nr should be at least 1 by then. right?

yeah, so i neglected the ++ line.
it seems OK to have the assignment after that.

lubomir
--


More information about the subsurface mailing list