Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge-ort: only do pointer arithmetic for non-empty lists #930

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 3 additions & 12 deletions merge-ort.c
Expand Up @@ -2493,20 +2493,11 @@ static void write_tree(struct object_id *result_oid,
size_t maxlen = 0, extra;
unsigned int nr = versions->nr - offset;
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;
QSORT(relevant_entries.items, relevant_entries.nr, tree_entry_order);
assert(offset <= versions->nr);
if (versions->nr)
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 */
Expand Down