git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] shallow.c: make paint_alloc slightly more robust
@ 2016-12-02 20:31 Rasmus Villemoes
  2016-12-02 20:31 ` [PATCH 2/4] shallow.c: avoid theoretical pointer wrap-around Rasmus Villemoes
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Rasmus Villemoes @ 2016-12-02 20:31 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy, Jeff King,
	Rasmus Villemoes

I have no idea if this is a real issue, but it's not obvious to me that
paint_alloc cannot be called with info->nr_bits greater than about
4M (\approx 8*COMMIT_SLAB_SIZE). In that case the new slab would be too
small. So just round up the allocation to the maximum of
COMMIT_SLAB_SIZE and size.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
 shallow.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/shallow.c b/shallow.c
index 4d0b005..e21534a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -445,11 +445,13 @@ static uint32_t *paint_alloc(struct paint_info *info)
 	unsigned size = nr * sizeof(uint32_t);
 	void *p;
 	if (!info->slab_count || info->free + size > info->end) {
+		unsigned alloc_size = size < COMMIT_SLAB_SIZE ?
+			COMMIT_SLAB_SIZE : size;
 		info->slab_count++;
 		REALLOC_ARRAY(info->slab, info->slab_count);
-		info->free = xmalloc(COMMIT_SLAB_SIZE);
+		info->free = xmalloc(alloc_size);
 		info->slab[info->slab_count - 1] = info->free;
-		info->end = info->free + COMMIT_SLAB_SIZE;
+		info->end = info->free + alloc_size;
 	}
 	p = info->free;
 	info->free += size;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-12-07 23:43 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-02 20:31 [PATCH 1/4] shallow.c: make paint_alloc slightly more robust Rasmus Villemoes
2016-12-02 20:31 ` [PATCH 2/4] shallow.c: avoid theoretical pointer wrap-around Rasmus Villemoes
2016-12-03  5:17   ` Jeff King
2016-12-02 20:31 ` [PATCH 3/4] shallow.c: bit manipulation tweaks Rasmus Villemoes
2016-12-03  5:21   ` Jeff King
2016-12-02 20:31 ` [PATCH 4/4] shallow.c: remove useless test Rasmus Villemoes
2016-12-03  5:24   ` Jeff King
2016-12-05 12:00     ` Duy Nguyen
2016-12-03  5:14 ` [PATCH 1/4] shallow.c: make paint_alloc slightly more robust Jeff King
2016-12-05 10:02   ` Duy Nguyen
2016-12-06 12:53 ` [PATCH v2 0/6] shallow.c improvements Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 1/6] shallow.c: rename fields in paint_info to better express their purposes Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 2/6] shallow.c: stop abusing COMMIT_SLAB_SIZE for paint_info's memory pools Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 3/6] shallow.c: make paint_alloc slightly more robust Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 4/6] shallow.c: avoid theoretical pointer wrap-around Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 5/6] shallow.c: bit manipulation tweaks Nguyễn Thái Ngọc Duy
2016-12-06 12:53   ` [PATCH v2 6/6] shallow.c: remove useless code Nguyễn Thái Ngọc Duy
2016-12-06 13:42   ` [PATCH v2 0/6] shallow.c improvements Jeff King
2016-12-06 13:47     ` Duy Nguyen
2016-12-07 23:42       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).