diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-04-16 13:53:34 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-04-16 13:53:34 -0700 |
commit | 257ae76ba9194c23a57a93033c499ee67bc1b037 (patch) | |
tree | 4ab8a2fe47490943026f80ada1019e2af7576693 | |
parent | 7bec8e7fa6175f51e79c55e28e6b2a547a986926 (diff) | |
parent | c1ea48a8f74cfb39f9c0583b26b79a038c3d9ab8 (diff) | |
download | git-257ae76ba9194c23a57a93033c499ee67bc1b037.tar.gz |
Merge branch 'ah/merge-ort-ubsan-fix'
Code clean-up for merge-ort backend.
* ah/merge-ort-ubsan-fix:
merge-ort: only do pointer arithmetic for non-empty lists
-rw-r--r-- | merge-ort.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/merge-ort.c b/merge-ort.c index d1f4cf8a1f..b1795d838e 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2653,23 +2653,15 @@ static void write_tree(struct object_id *result_oid, size_t hash_size) { size_t maxlen = 0, extra; - unsigned int nr = versions->nr - offset; + unsigned int nr; struct strbuf buf = STRBUF_INIT; - struct string_list relevant_entries = STRING_LIST_INIT_NODUP; int i; - /* - * We want to sort the last (versions->nr-offset) entries in versions. - * Do so by abusing the string_list API a bit: make another string_list - * that contains just those entries and then sort them. - * - * We won't use relevant_entries again and will let it just pop off the - * stack, so there won't be allocation worries or anything. - */ - relevant_entries.items = versions->items + offset; - relevant_entries.nr = versions->nr - offset; - /* No need for STABLE_QSORT -- filenames must be unique */ - QSORT(relevant_entries.items, relevant_entries.nr, tree_entry_order); + assert(offset <= versions->nr); + nr = versions->nr - offset; + if (versions->nr) + /* No need for STABLE_QSORT -- filenames must be unique */ + QSORT(versions->items + offset, nr, tree_entry_order); /* Pre-allocate some space in buf */ extra = hash_size + 8; /* 8: 6 for mode, 1 for space, 1 for NUL char */ |