summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3a55602)
raw | patch | inline | side by side (parent: 3a55602)
author | Shawn O. Pearce <spearce@spearce.org> | |
Wed, 7 Mar 2007 01:44:19 +0000 (20:44 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 7 Mar 2007 19:02:33 +0000 (11:02 -0800) |
As we permit up to 2^32-1 objects in a single packfile we cannot
use a signed int to represent the object offset within a packfile,
after 2^31-1 objects we will start seeing negative indexes and
error out or compute bad addresses within the mmap'd index.
This is a minor cleanup that does not introduce any significant
logic changes. It is roach free.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
use a signed int to represent the object offset within a packfile,
after 2^31-1 objects we will start seeing negative indexes and
error out or compute bad addresses within the mmap'd index.
This is a minor cleanup that does not introduce any significant
logic changes. It is roach free.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-fsck.c | patch | blob | history | |
cache.h | patch | blob | history | |
pack-check.c | patch | blob | history | |
sha1_file.c | patch | blob | history | |
sha1_name.c | patch | blob | history |
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 6abf498d2b391c97e9efcdb32da1cf3b5d566397..39cfc32818dc80d8bda04ff45fbf5996d1506922 100644 (file)
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
verify_pack(p, 0);
for (p = packed_git; p; p = p->next) {
- int num = num_packed_objects(p);
+ uint32_t i, num = num_packed_objects(p);
for (i = 0; i < num; i++) {
unsigned char sha1[20];
nth_packed_object_sha1(p, i, sha1);
index f3d7538aab0359f423999d050f764a44cf99eb15..63a093bcfd7970cf3d3edc6e1d81052a34e2afe8 100644 (file)
--- a/cache.h
+++ b/cache.h
extern unsigned char* use_pack(struct packed_git *, struct pack_window **, unsigned long, unsigned int *);
extern void unuse_pack(struct pack_window **);
extern struct packed_git *add_packed_git(char *, int, int);
-extern int num_packed_objects(const struct packed_git *p);
-extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*);
+extern uint32_t num_packed_objects(const struct packed_git *p);
+extern int nth_packed_object_sha1(const struct packed_git *, uint32_t, unsigned char*);
extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *);
extern void *unpack_entry(struct packed_git *, unsigned long, enum object_type *, unsigned long *);
extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
diff --git a/pack-check.c b/pack-check.c
index f248ac8c7aa0efb976528e5f7941fef1f6b5bc91..7c82f6795e9c7228bed39d4f449ab768abb85551 100644 (file)
--- a/pack-check.c
+++ b/pack-check.c
SHA_CTX ctx;
unsigned char sha1[20];
unsigned long offset = 0, pack_sig = p->pack_size - 20;
- int nr_objects, err, i;
+ uint32_t nr_objects, i;
+ int err;
/* Note that the pack header checks are actually performed by
* use_pack when it first opens the pack file. If anything
* we do not do scan-streaming check on the pack file.
*/
nr_objects = num_packed_objects(p);
- for (i = err = 0; i < nr_objects; i++) {
+ for (i = 0, err = 0; i < nr_objects; i++) {
unsigned char sha1[20];
void *data;
enum object_type type;
static void show_pack_info(struct packed_git *p)
{
- int nr_objects, i;
- unsigned int chain_histogram[MAX_CHAIN];
+ uint32_t nr_objects, i, chain_histogram[MAX_CHAIN];
nr_objects = num_packed_objects(p);
memset(chain_histogram, 0, sizeof(chain_histogram));
diff --git a/sha1_file.c b/sha1_file.c
index b17a8287958a5af4e197ed6114eee255d1bc1b79..54ffa7c70346306554b17ce1de29f2b5e94a67b2 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
void *idx_map;
uint32_t *index;
unsigned long idx_size;
- int nr, i;
+ uint32_t nr, i;
int fd = open(path, O_RDONLY);
struct stat st;
if (fd < 0)
nr = 0;
for (i = 0; i < 256; i++) {
- unsigned int n = ntohl(index[i]);
+ uint32_t n = ntohl(index[i]);
if (n < nr) {
munmap(idx_map, idx_size);
return error("non-monotonic index %s", path);
return data;
}
-int num_packed_objects(const struct packed_git *p)
+uint32_t num_packed_objects(const struct packed_git *p)
{
/* See check_packed_git_idx() */
return (p->index_size - 20 - 20 - 4*256) / 24;
}
-int nth_packed_object_sha1(const struct packed_git *p, int n,
+int nth_packed_object_sha1(const struct packed_git *p, uint32_t n,
unsigned char* sha1)
{
void *index = p->index_base + 256;
- if (n < 0 || num_packed_objects(p) <= n)
+ if (num_packed_objects(p) <= n)
return -1;
hashcpy(sha1, (unsigned char *) index + (24 * n) + 4);
return 0;
diff --git a/sha1_name.c b/sha1_name.c
index 0781477a71ac4d76a1b8783868d6649cae7f8507..31812d3d26c7b33eaf3fe76f3145fd1fc193366d 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -76,10 +76,10 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
prepare_packed_git();
for (p = packed_git; p && found < 2; p = p->next) {
- unsigned num = num_packed_objects(p);
- unsigned first = 0, last = num;
+ uint32_t num = num_packed_objects(p);
+ uint32_t first = 0, last = num;
while (first < last) {
- unsigned mid = (first + last) / 2;
+ uint32_t mid = (first + last) / 2;
unsigned char now[20];
int cmp;