git/xdiff
Jeff King 36c8319724 xdiff: use xmalloc/xrealloc
Most of xdiff uses a bare malloc() to allocate memory, and returns an
error when we get NULL. However, there are a few spots which don't check
the return value and may segfault, including at least xdl_merge() and
xpatience.c's find_longest_common_sequence().

Let's use xmalloc() everywhere instead, so that we get a graceful die()
for these cases, without having to do further auditing. This does mean
the existing cases which check errors will now die() instead of
returning an error up the stack. But:

  - that's how the rest of Git behaves already for malloc errors

  - all of the callers of xdi_diff(), etc, die upon seeing an error

So while we might one day want to fully lib-ify the diff code and make
it possible to use as part of a long-running process, we're not close to
that now. And because we're just tweaking the xdl_malloc() macro here,
we're not really moving ourselves any further away from that. We
could, for example, simplify some of the functions which handle malloc()
errors which can no longer occur. But that would probably be taking us
in the wrong direction.

This also makes our malloc handling more consistent with the rest of
Git, including enforcing GIT_ALLOC_LIMIT and trying to reclaim pack
memory when needed.

Reported-by: 王健强 <jianqiang.wang@securitygossip.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-12 13:34:17 +09:00
..
xdiff.h xdiff: use xmalloc/xrealloc 2019-04-12 13:34:17 +09:00
xdiffi.c Merge branch 'sb/indent-heuristic-optim' 2018-08-17 13:09:57 -07:00
xdiffi.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xemit.c xdiff: show non-empty lines before functions with -W 2017-11-21 09:36:06 +09:00
xemit.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xhistogram.c xdiff/histogram: remove tail recursion 2018-07-23 10:12:16 -07:00
xinclude.h xdiff: use git-compat-util 2019-04-12 13:34:17 +09:00
xmacros.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xmerge.c Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xpatience.c diff: support anchoring line(s) 2017-11-28 10:40:04 +09:00
xprepare.c Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xprepare.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xtypes.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xutils.c xdiff: provide a separate emit callback for hunks 2018-11-02 20:43:02 +09:00
xutils.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00