1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-01 06:47:52 +01:00
git/xdiff
Derrick Stolee 19716b21a4 cleanup: fix possible overflow errors in binary search
A common mistake when writing binary search is to allow possible
integer overflow by using the simple average:

	mid = (min + max) / 2;

Instead, use the overflow-safe version:

	mid = min + (max - min) / 2;

This translation is safe since the operation occurs inside a loop
conditioned on "min < max". The included changes were found using
the following git grep:

	git grep '/ *2;' '*.c'

Making this cleanup will prevent future review friction when a new
binary search is contructed based on existing code.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-10 08:57:24 +09:00
..
xdiff.h diff: retire "compaction" heuristics 2016-12-23 12:32:22 -08:00
xdiffi.c diff: retire "compaction" heuristics 2016-12-23 12:32:22 -08:00
xdiffi.h
xemit.c xdiff -W: relax end-of-file function detection 2017-01-15 16:08:11 -08:00
xemit.h
xhistogram.c
xinclude.h
xmacros.h
xmerge.c Merge branch 'ps/plug-xdl-merge-leak' 2016-02-26 13:37:22 -08:00
xpatience.c cleanup: fix possible overflow errors in binary search 2017-10-10 08:57:24 +09:00
xprepare.c xdiff/xprepare: fix a memory leak 2016-03-04 15:51:08 -08:00
xprepare.h
xtypes.h
xutils.c xdiff: drop XDL_FAST_HASH 2016-12-06 13:27:11 -08:00
xutils.h