summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-03-06 20:44:19 -0500
committerJunio C Hamano <junkio@cox.net>2007-03-07 11:02:33 -0800
commit326bf396778bc9ab8f9e253bb514e7f41ef1502b (patch)
tree41a09c2642dbd03db6b6b6cf3394e048b7661800 /sha1_file.c
parent3a55602eeca4ac8670e8698a7187e18b95683344 (diff)
downloadgit-326bf396778bc9ab8f9e253bb514e7f41ef1502b.tar.gz
Use uint32_t for all packed object counts.
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>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sha1_file.c b/sha1_file.c
index b17a828795..54ffa7c703 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -437,7 +437,7 @@ static int check_packed_git_idx(const char *path,
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)
@@ -472,7 +472,7 @@ static int check_packed_git_idx(const char *path,
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);
@@ -1339,17 +1339,17 @@ void *unpack_entry(struct packed_git *p, unsigned long obj_offset,
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;