zlib: initialize git_zstream in git_deflate_init{,_gzip,_raw}
PATCH 1/1 zlib: initialize git_zstream in git_deflate_init{,_gzip,_raw}
Clear the git_zstream variable at the start of git_deflate_init() etc. so that callers don't have to do that.
Signed-off-by Rene Scharfe <[email protected]>
--- archive-zip.c | 2 -- builtin/index-pack.c | 1 - builtin/pack-objects.c | 2 -- bulk-checkin.c | 1 - diff.c | 1 - fast-import.c | 3 --- http-push.c | 1 - remote-curl.c | 1 - sha1_file.c | 1 - zlib.c | 2 ++ 10 files changed, 2 insertions(+), 13 deletions(-)
archive-zip.c +0 -2
@@ -120,7 +120,6 @@ static void *zlib_deflate_raw(void *data, unsigned long size,void *buffer;int result; -memset (&stream,0 ,sizeof (stream));git_deflate_init_raw (&stream, compression_level); maxsize =git_deflate_bound (&stream, size); buffer =xmalloc (maxsize);
@@ -349,7 +348,6 @@ static int write_zip_entry(struct archiver_args *args,size_t out_len;unsigned char compressed[STREAM_BUFFER_SIZE *2 ]; -memset (&zstream,0 ,sizeof (zstream));git_deflate_init_raw (&zstream, args->compression_level); compressed_size =0 ;
builtin/index-pack.c +0 -1
@@ -1204,7 +1204,6 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)int status;unsigned char outbuf[4096 ]; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); stream.next_in = in; stream.avail_in = size;
builtin/pack-objects.c +0 -2
@@ -125,7 +125,6 @@ static unsigned long do_compress(void **pptr, unsigned long size)void *in, *out;unsigned long maxsize; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, pack_compression_level); maxsize =git_deflate_bound (&stream, size);
@@ -153,7 +152,6 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fiunsigned char obuf[1024 *16 ];unsigned long olen =0 ; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, pack_compression_level);for (;;) {
bulk-checkin.c +0 -1
@@ -105,7 +105,6 @@ static int stream_to_pack(struct bulk_checkin_state *state,int write_object = (flags &HASH_WRITE_OBJECT );off_t offset =0 ; -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level); hdrlen =encode_in_pack_object_header (type, size, obuf);
diff.c +0 -1
@@ -2093,7 +2093,6 @@ static unsigned char *deflate_it(char *data,unsigned char *deflated;git_zstream stream; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); bound =git_deflate_bound (&stream, size); deflated =xmalloc (bound);
fast-import.c +0 -3
@@ -1062,7 +1062,6 @@ static int store_object( }else delta =NULL ; -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level);if (delta) { s.next_in = delta;
@@ -1090,7 +1089,6 @@ static int store_object(free (delta); delta =NULL ; -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level); s.next_in = (void *)dat->buf; s.avail_in = dat->len;
@@ -1190,7 +1188,6 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)crc32_begin (pack_file); -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level); hdrlen =encode_in_pack_object_header (OBJ_BLOB , len, out_buf);
http-push.c +0 -1
@@ -365,7 +365,6 @@ static void start_put(struct transfer_request *request) hdrlen =sprintf (hdr,"%s %lu" ,typename (type), len) +1 ;/* Set it up */ -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); size =git_deflate_bound (&stream, len + hdrlen);strbuf_init (&request->buffer.buf, size);
remote-curl.c +0 -1
@@ -567,7 +567,6 @@ retry:git_zstream stream;int ret; -memset (&stream,0 ,sizeof (stream));git_deflate_init_gzip (&stream,Z_BEST_COMPRESSION ); gzip_size =git_deflate_bound (&stream, rpc->len); gzip_body =xmalloc (gzip_size);
sha1_file.c +0 -1
@@ -2943,7 +2943,6 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, }/* Set it up */ -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); stream.next_out = compressed; stream.avail_out =sizeof (compressed);
zlib.c +2 -0
@@ -159,6 +159,7 @@ void git_deflate_init(git_zstream *strm, int level) {int status; +memset (strm,0 ,sizeof (*strm));zlib_pre_call (strm); status =deflateInit (&strm->z, level);zlib_post_call (strm);
@@ -172,6 +173,7 @@ static void do_git_deflate_init(git_zstream *strm, int level, int windowBits) {int status; +memset (strm,0 ,sizeof (*strm));zlib_pre_call (strm); status = deflateInit2(&strm->z, level, Z_DEFLATED, windowBits,
Signature · 1 line
2.3.1
Quoted 4 lines · René Scharfe
Clear the
git_zstreamvariable at the start ofgit_deflate_init()etc. so that callers don't have to do that.Signed-off-by Rene Scharfe <[email protected]>
Nice. "git grep -B1 git_deflate_init" tells me that all existing callers of the function do this memset(). Clearly the above is a very good idea and is a safe and sane thing to do.
Thanks.
Quoted 173 lines
--- archive-zip.c | 2 -- builtin/index-pack.c | 1 - builtin/pack-objects.c | 2 -- bulk-checkin.c | 1 - diff.c | 1 - fast-import.c | 3 --- http-push.c | 1 - remote-curl.c | 1 - sha1_file.c | 1 - zlib.c | 2 ++ 10 files changed, 2 insertions(+), 13 deletions(-)archive-zip.c +0
-2@@ -120,7 +120,6 @@ static void *zlib_deflate_raw(void *data, unsigned long size,void *buffer;int result; -memset (&stream,0 ,sizeof (stream));git_deflate_init_raw (&stream, compression_level); maxsize =git_deflate_bound (&stream, size); buffer =xmalloc (maxsize);@@ -349,7 +348,6 @@ static int write_zip_entry(struct archiver_args *args,size_t out_len;unsigned char compressed[STREAM_BUFFER_SIZE *2 ]; -memset (&zstream,0 ,sizeof (zstream));git_deflate_init_raw (&zstream, args->compression_level); compressed_size =0 ;builtin/index-pack.c +0
-1@@ -1204,7 +1204,6 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)int status;unsigned char outbuf[4096 ]; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); stream.next_in = in; stream.avail_in = size;builtin/pack-objects.c +0
-2@@ -125,7 +125,6 @@ static unsigned long do_compress(void **pptr, unsigned long size)void *in, *out;unsigned long maxsize; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, pack_compression_level); maxsize =git_deflate_bound (&stream, size);@@ -153,7 +152,6 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fiunsigned char obuf[1024 *16 ];unsigned long olen =0 ; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, pack_compression_level);for (;;) {bulk-checkin.c +0
-1@@ -105,7 +105,6 @@ static int stream_to_pack(struct bulk_checkin_state *state,int write_object = (flags &HASH_WRITE_OBJECT );off_t offset =0 ; -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level); hdrlen =encode_in_pack_object_header (type, size, obuf);diff.c +0
-1@@ -2093,7 +2093,6 @@ static unsigned char *deflate_it(char *data,unsigned char *deflated;git_zstream stream; -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); bound =git_deflate_bound (&stream, size); deflated =xmalloc (bound);fast-import.c +0
-3@@ -1062,7 +1062,6 @@ static int store_object( }else delta =NULL ; -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level);if (delta) { s.next_in = delta;@@ -1090,7 +1089,6 @@ static int store_object(free (delta); delta =NULL ; -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level); s.next_in = (void *)dat->buf; s.avail_in = dat->len;@@ -1190,7 +1188,6 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)crc32_begin (pack_file); -memset (&s,0 ,sizeof (s));git_deflate_init (&s, pack_compression_level); hdrlen =encode_in_pack_object_header (OBJ_BLOB , len, out_buf);http-push.c +0
-1@@ -365,7 +365,6 @@ static void start_put(struct transfer_request *request) hdrlen =sprintf (hdr,"%s %lu" ,typename (type), len) +1 ;/* Set it up */ -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); size =git_deflate_bound (&stream, len + hdrlen);strbuf_init (&request->buffer.buf, size);remote-curl.c +0
-1@@ -567,7 +567,6 @@ retry:git_zstream stream;int ret; -memset (&stream,0 ,sizeof (stream));git_deflate_init_gzip (&stream,Z_BEST_COMPRESSION ); gzip_size =git_deflate_bound (&stream, rpc->len); gzip_body =xmalloc (gzip_size);sha1_file.c +0
-1@@ -2943,7 +2943,6 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, }/* Set it up */ -memset (&stream,0 ,sizeof (stream));git_deflate_init (&stream, zlib_compression_level); stream.next_out = compressed; stream.avail_out =sizeof (compressed);zlib.c +2
-0@@ -159,6 +159,7 @@ void git_deflate_init(git_zstream *strm, int level) {int status; +memset (strm,0 ,sizeof (*strm));zlib_pre_call (strm); status =deflateInit (&strm->z, level);zlib_post_call (strm);@@ -172,6 +173,7 @@ static void do_git_deflate_init(git_zstream *strm, int level, int windowBits) {int status; +memset (strm,0 ,sizeof (*strm));zlib_pre_call (strm); status = deflateInit2(&strm->z, level, Z_DEFLATED, windowBits,