Re: Fix up ugly open-coded "alloc_nr()" user in object.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jun 17, 2007 at 12:15:06AM +0200, Olivier Galibert wrote:

> > +	ALLOC_GROW(array->objects, array->nr, array->alloc);
> 
> Unless the ALLOC_GROW semantics are weird, shouldn't that be:
>   ALLOC_GROW(array->objects, array->nr+1, array->alloc);

The semantics are weird. They never seemed so to me before, since it was
replacing some "grow by 1" areas where it is natural to assume that you
need just one spot more. But the way Junio commented it and tweaked it,
it can handle arbitrary growth (which is much better), but that means we
are overly conservative about when to grow.

Junio, patch is below (call-sites using bare 'nr' need to be 'nr+1', but
I will fix those up in a separate patch since they are in next and this
is in master).

-- >8 --
fix ALLOC_GROW off-by-one

The ALLOC_GROW macro will never let us fill the array completely,
instead allocating an extra chunk if that would be the case. This is
because the 'nr' argument was originally treated as "how much we do have
now" instead of "how much do we want". The latter makes much more
sense because you can grow by more than one item.

This off-by-one never resulted in an error because it meant we were
overly conservative about when to allocate. Any callers which passed
"how we have now" need to be updated, or they will fail to allocate
enough.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
 cache.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cache.h b/cache.h
index c914c1c..ed83d92 100644
--- a/cache.h
+++ b/cache.h
@@ -234,7 +234,7 @@ extern void verify_non_filename(const char *prefix, const char *name);
  */
 #define ALLOC_GROW(x, nr, alloc) \
 	do { \
-		if ((nr) >= alloc) { \
+		if ((nr) > alloc) { \
 			if (alloc_nr(alloc) < (nr)) \
 				alloc = (nr); \
 			else \
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux