git/list[1] front-page[2] threads[3] people[4] search[5] about
 

pack-objects: Fix segfault when object count is less than thread count

From
Sergey Vlasov <vsu@altlinux.ru>
Date
Jan 21, 2008, 14:35 UTC
Message-ID
<1200926145-14625-1-git-send-email-vsu@altlinux.ru>

When partitioning the work amongst threads, dividing the number of objects by the number of threads may return 0 when there are less objects than threads; this will cause the subsequent code to segfault when accessing list[sub_size-1]. Fix this by ensuring that sub_size is not zero if there is at least one object to process.

Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
---
 builtin-pack-objects.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index ec10238..cdf8aae 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1665,6 +1665,9 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
 	for (i = 0; i < delta_search_threads; i++) {
 		unsigned sub_size = list_size / (delta_search_threads - i);
 
+		if (sub_size == 0 && list_size >= 1)
+			sub_size = 1;
+
 		p[i].window = window;
 		p[i].depth = depth;
 		p[i].processed = processed;
-- 
1.5.4.rc4.14.gd50a3
Next: Johannes Sixt
Message 1 of 6 in “pack-objects: Fix segfault when object count is less than thread count”
  1. Sergey VlasovJan 21, 2008
  2. Johannes SixtJan 21, 2008
  3. Nicolas PitreJan 21, 2008
  4. Nicolas PitreJan 21, 2008
  5. Sergey VlasovJan 21, 2008
  6. Nicolas PitreJan 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.