summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-10-11 14:52:24 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-10-11 14:52:24 +0900
commit7245ee3d6cd0c7eea81b57260badc6fcda5d8ffd (patch)
tree2fc0707b95acb28a22bc07c62a83878523d00ff0 /builtin
parentMerge branch 'tb/complete-describe' (diff)
parentcleanup: fix possible overflow errors in binary search (diff)
downloadtgif-7245ee3d6cd0c7eea81b57260badc6fcda5d8ffd.tar.xz
Merge branch 'ds/avoid-overflow-in-midpoint-computation'
Code clean-up. * ds/avoid-overflow-in-midpoint-computation: cleanup: fix possible overflow errors in binary search
Diffstat (limited to 'builtin')
-rw-r--r--builtin/index-pack.c4
-rw-r--r--builtin/pack-objects.c2
-rw-r--r--builtin/unpack-objects.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index f2be145e12..8ec459f522 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -633,7 +633,7 @@ static int find_ofs_delta(const off_t offset, enum object_type type)
int first = 0, last = nr_ofs_deltas;
while (first < last) {
- int next = (first + last) / 2;
+ int next = first + (last - first) / 2;
struct ofs_delta_entry *delta = &ofs_deltas[next];
int cmp;
@@ -687,7 +687,7 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
int first = 0, last = nr_ref_deltas;
while (first < last) {
- int next = (first + last) / 2;
+ int next = first + (last - first) / 2;
struct ref_delta_entry *delta = &ref_deltas[next];
int cmp;
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 5ee2c48ffb..6e77dfd444 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1277,7 +1277,7 @@ static int done_pbase_path_pos(unsigned hash)
int lo = 0;
int hi = done_pbase_paths_num;
while (lo < hi) {
- int mi = (hi + lo) / 2;
+ int mi = lo + (hi - lo) / 2;
if (done_pbase_paths[mi] == hash)
return mi;
if (done_pbase_paths[mi] < hash)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 689a29fac1..62ea264c46 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -394,7 +394,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
lo = 0;
hi = nr;
while (lo < hi) {
- mid = (lo + hi)/2;
+ mid = lo + (hi - lo) / 2;
if (base_offset < obj_list[mid].offset) {
hi = mid;
} else if (base_offset > obj_list[mid].offset) {