diff --git a/unpack-objects.c b/unpack-objects.c
index a62eeb432d33bdfe4b609e11d48c72a81832874b..a792b92ece0770e5c2305b26d70eb26ee51d26c7 100644 (file)
--- a/unpack-objects.c
+++ b/unpack-objects.c
unsigned int nr;
int i;
- if (index_size < 4*256)
+ if (index_size < 4*256 + 20)
return error("index file too small");
nr = 0;
for (i = 0; i < 256; i++) {
return error("non-monotonic index");
nr = n;
}
- if (index_size != 4*256 + nr * 24) {
- printf("index_size=%lu, expected %u (%u)\n",
- index_size, 4*256 + nr * 24, nr);
+ /*
+ * Total size:
+ * - 256 index entries 4 bytes each
+ * - 24-byte entries * nr (20-byte sha1 + 4-byte offset)
+ * - 20-byte SHA1 of the packfile
+ * - 20-byte SHA1 file checksum
+ */
+ if (index_size != 4*256 + nr * 24 + 20 + 20)
return error("wrong index file size");
- }
nr_entries = nr;
pack_list = xmalloc(nr * sizeof(struct pack_entry *));
do {
int mi = (lo + hi) / 2;
int cmp = memcmp(index + 24 * mi + 4, sha1, 20);
-printf("lo=%d mi=%d hi=%d cmp=%d\n", lo, mi, hi, cmp);
if (!cmp) {
*ent = index + 24 * mi;
return 1;