@matheusbsbs / matheus-bagliano / commits / c00e657df2
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 1, 2010 at 20:03 UTC c00e657df23d9e83d86a79657ff9061b1c2d357b
2 files changed +4 -4
cache.h
+1 -1
@@ -701,7 +701,7 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
701 return read_sha1_file_repl(sha1, type, size, NULL);
702 }
703 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);
705 extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
706 extern int force_object_loose(const unsigned char *sha1, time_t mtime);
707
sha1_file.c
+3 -3
@@ -2271,7 +2271,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
2271 }
2272
2273 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)
2275 {
2276 int fd, ret;
2277 unsigned char compressed[4096];
@@ -2307,7 +2307,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
2307 git_SHA1_Update(&c, hdr, hdrlen);
2308
2309 /* Then the data itself.. */
2310 - stream.next_in = buf;
2310 + stream.next_in = (void *)buf;
2311 stream.avail_in = len;
2312 do {
2313 unsigned char *in0 = stream.next_in;
@@ -2342,7 +2342,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
2342 return move_temp_to_file(tmpfile, filename);
2343 }
2344
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)
2346 {
2347 unsigned char sha1[20];
2348 char hdr[32];