From: Jeff King Date: Tue, 10 Jun 2014 21:49:11 GMT Subject: Re: [PATCH 03/15] do not create "struct commit" with xcalloc Message-ID: <20140610214911.GB19107@sigill.intra.peff.net> In-Reply-To: On Tue, Jun 10, 2014 at 02:35:48PM -0700, Junio C Hamano wrote: > Jeff King writes: > > > In both blame and merge-recursive, we sometimes create a > > "fake" commit struct for convenience (e.g., to represent the > > HEAD state as if we would commit it). By allocating > > ourselves rather than using alloc_commit_node, we do not > > properly set the "index" field of the commit. This can > > produce subtle bugs if we then use commit-slab on the > > resulting commit, as we will share the "0" index with > > another commit. > > The change I see here is all good, but I wonder if it is too late to > start the real index from 1 and catch anything that has 0 index with > a BUG("do not hand-allocate a commit"). Yeah, I had a similar thought while writing the series. I do not think it is too late at all. It would just waste one commit's worth of memory in the slab, but that is not a big deal. Other than slab_at, no callers should care. It would cost an extra conditional in each call to slab_at. That probably doesn't matter, though the original goal was to make slab_at as fast as an indirect pointer dereference (it's not quite these days, though, as we have to do a little division to find the right section of the slab). -Peff