Jeff King 5f46e610cb diff: check for merge bases before assigning sym->base
In symdiff_prepare(), we iterate over the set of parsed objects to pick
out any symmetric differences, including the left, right, and base
elements. We assign the results into pointers in a "struct symdiff", and
then complain if we didn't find a base, like so:

    sym->left = rev->pending.objects[lpos].name;
    sym->right = rev->pending.objects[rpos].name;
    sym->base = rev->pending.objects[basepos].name;
    if (basecount == 0)
            die(_("%s...%s: no merge base"), sym->left, sym->right);

But the least lines are backwards. If basecount is 0, then basepos will
be -1, and we will access memory outside of the pending array. This
isn't usually that big a deal, since we don't do anything besides a
single pointer-sized read before exiting anyway, but it does violate the
C standard, and of course memory-checking tools like ASan complain.

Let's put the basecount check first. Note that we haveto split it from
the other assignments, since the die() relies on sym->left and
sym->right having been assigned (this isn't strictly necessary, but is
easier to read than dereferencing the pending array again).

Reported-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-07-08 13:57:18 -07:00
..
2020-02-14 12:54:19 -08:00
2019-11-11 11:46:29 +09:00
2020-02-17 13:22:17 -08:00
2020-03-02 15:07:19 -08:00
2019-09-30 13:19:32 +09:00
2019-05-13 14:22:54 +09:00
2020-02-10 09:04:45 -08:00
2020-03-12 14:28:01 -07:00
2019-11-10 18:02:14 +09:00
2019-12-10 13:11:41 -08:00
2020-03-05 10:43:02 -08:00
2020-03-09 11:21:19 -07:00
2019-06-19 08:19:21 -07:00