X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=diff-delta.c;h=fa16d06c8d1e85a458428c673cb2f589857f5424;hb=1efca00ad8fc1a7ad04d80a76ba852e0cce847b0;hp=c61887518874d550f66d2d52bd7559d023fcb176;hpb=7dd0d0bf52e3b3bcdca2ea31368e16c367a2505f;p=git.git diff --git a/diff-delta.c b/diff-delta.c index c61887518..fa16d06c8 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -22,6 +22,7 @@ #include #include "delta.h" +#include "git-compat-util.h" /* maximum hash entry list for the same hash bucket */ #define HASH_LIMIT 64 @@ -131,7 +132,7 @@ struct delta_index { const void *src_buf; unsigned long src_size; unsigned int hash_mask; - struct index_entry *hash[0]; + struct index_entry *hash[FLEX_ARRAY]; }; struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) @@ -147,11 +148,11 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) return NULL; /* Determine index hash size. Note that indexing skips the - first byte to allow for optimizing the rabin polynomial + first byte to allow for optimizing the Rabin's polynomial initialization in create_delta(). */ entries = (bufsize - 1) / RABIN_WINDOW; hsize = entries / 4; - for (i = 4; (1 << i) < hsize && i < 31; i++); + for (i = 4; (1u << i) < hsize && i < 31; i++); hsize = 1 << i; hmask = hsize - 1; @@ -199,13 +200,12 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) entry->next = hash[i]; hash[i] = entry++; hash_count[i]++; - entries--; } } /* * Determine a limit on the number of entries in the same hash - * bucket. This guard us against patological data sets causing + * bucket. This guards us against pathological data sets causing * really bad hash distribution with most entries in the same hash * bucket that would bring us to O(m*n) computing costs (m and n * corresponding to reference and target buffer sizes). @@ -230,10 +230,6 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) } free(hash_count); - /* If we didn't use all hash entries, free the unused memory. */ - if (entries) - index = realloc(index, memsize - entries * sizeof(*entry)); - return index; } @@ -244,7 +240,7 @@ void free_delta_index(struct delta_index *index) /* * The maximum size for any opcode sequence, including the initial header - * plus rabin window plus biggest copy. + * plus Rabin window plus biggest copy. */ #define MAX_OP_SIZE (5 + 5 + 1 + RABIN_WINDOW + 7) @@ -288,7 +284,7 @@ create_delta(const struct delta_index *index, ref_data = index->src_buf; ref_top = ref_data + index->src_size; data = trg_buf; - top = trg_buf + trg_size; + top = (const unsigned char *) trg_buf + trg_size; outpos++; val = 0; @@ -396,7 +392,7 @@ create_delta(const struct delta_index *index, outsize = max_size + MAX_OP_SIZE + 1; if (max_size && outpos > max_size) break; - out = realloc(out, outsize); + out = xrealloc(out, outsize); if (!out) { free(tmp); return NULL;