Skip to content

Commit c00e657

Browse files
peffgitster
authored andcommitted
fix const-correctness of write_sha1_file
These should take const buffers as input data, but zlib's next_in pointer is not const-correct. Let's fix it at the zlib level, though, so the cast happens in one obvious place. This should be safe, as a similar cast is used in zlib's example code for a const array. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 890a13a commit c00e657

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
701701
return read_sha1_file_repl(sha1, type, size, NULL);
702702
}
703703
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
704-
extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
704+
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
705705
extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
706706
extern int force_object_loose(const unsigned char *sha1, time_t mtime);
707707

sha1_file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
22712271
}
22722272

22732273
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
2274-
void *buf, unsigned long len, time_t mtime)
2274+
const void *buf, unsigned long len, time_t mtime)
22752275
{
22762276
int fd, ret;
22772277
unsigned char compressed[4096];
@@ -2307,7 +2307,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
23072307
git_SHA1_Update(&c, hdr, hdrlen);
23082308

23092309
/* Then the data itself.. */
2310-
stream.next_in = buf;
2310+
stream.next_in = (void *)buf;
23112311
stream.avail_in = len;
23122312
do {
23132313
unsigned char *in0 = stream.next_in;
@@ -2342,7 +2342,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
23422342
return move_temp_to_file(tmpfile, filename);
23432343
}
23442344

2345-
int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
2345+
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
23462346
{
23472347
unsigned char sha1[20];
23482348
char hdr[32];

0 commit comments

Comments
 (0)