sha1_file.c: use ALLOC_GROW() in pretend_sha1_file()
authorDmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>
Mon, 3 Mar 2014 22:32:02 +0000 (02:32 +0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Mar 2014 22:54:58 +0000 (14:54 -0800)
Helped-by: He Sun <sunheehnus@gmail.com>
Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c
index 6e8c05d10825ee93d8248f749d4bef513d772be4..2af06f842324485191204b8c5e46436156feb903 100644 (file)
@@ -2626,12 +2626,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
        hash_sha1_file(buf, len, typename(type), sha1);
        if (has_sha1_file(sha1) || find_cached_object(sha1))
                return 0;
-       if (cached_object_alloc <= cached_object_nr) {
-               cached_object_alloc = alloc_nr(cached_object_alloc);
-               cached_objects = xrealloc(cached_objects,
-                                         sizeof(*cached_objects) *
-                                         cached_object_alloc);
-       }
+       ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
        co = &cached_objects[cached_object_nr++];
        co->size = len;
        co->type = type;