Skip to content

Commit af89690

Browse files
PhilipOakleydscho
authored andcommitted
hash algorithms: use size_t for section lengths
Continue walking the code path for the >4GB `hash-object --literally` test to the hash algorithm step for LLP64 systems. This patch lets the SHA1DC code use `size_t`, making it compatible with LLP64 data models (as used e.g. by Windows). The interested reader of this patch will note that we adjust the signature of the `git_SHA1DCUpdate()` function without updating _any_ call site. This certainly puzzled at least one reviewer already, so here is an explanation: This function is never called directly, but always via the macro `platform_SHA1_Update`, which is usually called via the macro `git_SHA1_Update`. However, we never call `git_SHA1_Update()` directly in `struct git_hash_algo`. Instead, we call `git_hash_sha1_update()`, which is defined thusly: static void git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len) { git_SHA1_Update(&ctx->sha1, data, len); } i.e. it contains an implicit downcast from `size_t` to `unsigned long` (before this here patch). With this patch, there is no downcast anymore. With this patch, finally, the t1007-hash-object.sh "files over 4GB hash literally" test case is fixed. Signed-off-by: Philip Oakley <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent db6ffba commit af89690

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

object-file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ void *read_object_with_reference(struct repository *r,
17861786
}
17871787

17881788
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
1789-
const void *buf, unsigned long len,
1789+
const void *buf, size_t len,
17901790
struct object_id *oid,
17911791
char *hdr, size_t *hdrlen)
17921792
{
@@ -1806,7 +1806,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
18061806
/* Generate the header */
18071807
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
18081808

1809-
/* Sha1.. */
1809+
/* Hash (function pointers) computation */
18101810
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
18111811
}
18121812

sha1dc_git.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
2525
/*
2626
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
2727
*/
28-
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
28+
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len)
2929
{
3030
const char *data = vdata;
31-
/* We expect an unsigned long, but sha1dc only takes an int */
3231
while (len > INT_MAX) {
3332
SHA1DCUpdate(ctx, data, INT_MAX);
3433
data += INT_MAX;

sha1dc_git.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void git_SHA1DCInit(SHA1_CTX *);
1515
#endif
1616

1717
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
18-
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
18+
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, size_t len);
1919

2020
#define platform_SHA_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */
2121
#define platform_SHA_CTX SHA1_CTX

t/t1007-hash-object.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ test_expect_success '--literally with extra-long type' '
252252
echo example | git hash-object -t $t --literally --stdin
253253
'
254254

255-
test_expect_failure EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
255+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
256256
'files over 4GB hash literally' '
257257
test-tool genzeros $((5*1024*1024*1024)) >big &&
258258
test_oid large5GB >expect &&

0 commit comments

Comments
 (0)