diff options
author | René Scharfe <l.s.r@web.de> | 2019-06-13 19:51:56 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-06-13 11:28:53 -0700 |
commit | 568a05c5ecb8e3a01fcb90d0f81857f49ef2add8 (patch) | |
tree | e85ff4b06b04fd9427a417c7c7b41ad73c0bd6dc /usage.c | |
parent | Git 2.22 (diff) | |
download | tgif-568a05c5ecb8e3a01fcb90d0f81857f49ef2add8.tar.xz |
cleanup: fix possible overflow errors in binary search, part 2
Calculating the sum of two array indexes to find the midpoint between
them can overflow, i.e. code like this is unsafe for big arrays:
mid = (first + last) >> 1;
Make sure the intermediate value stays within the boundaries instead,
like this:
mid = first + ((last - first) >> 1);
The loop condition of the binary search makes sure that 'last' is
always greater than 'first', so this is safe as long as 'first' is
not negative. And that can be verified easily using the pre-context
of each change, except for name-hash.c, so add an assertion to that
effect there.
The unsafe calculations were found with:
git grep '(.*+.*) *>> *1'
This is a continuation of 19716b21a4 (cleanup: fix possible overflow
errors in binary search, 2017-10-08).
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'usage.c')
0 files changed, 0 insertions, 0 deletions