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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Mar 5, 2015 at 23:49 UTC 9a6f1287fb69c46c7895f987ffea558b13ae79d1
10 files changed +2 -13
archive-zip.c
-2
@@ -120,7 +120,6 @@ static void *zlib_deflate_raw(void *data, unsigned long size,
120 void *buffer;
121 int result;
122
123 - memset(&stream, 0, sizeof(stream));
123 git_deflate_init_raw(&stream, compression_level);
124 maxsize = git_deflate_bound(&stream, size);
125 buffer = xmalloc(maxsize);
@@ -349,7 +348,6 @@ static int write_zip_entry(struct archiver_args *args,
348 size_t out_len;
349 unsigned char compressed[STREAM_BUFFER_SIZE * 2];
350
352 - memset(&zstream, 0, sizeof(zstream));
351 git_deflate_init_raw(&zstream, args->compression_level);
352
353 compressed_size = 0;
builtin/index-pack.c
-1
@@ -1173,7 +1173,6 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)
1173 int status;
1174 unsigned char outbuf[4096];
1175
1176 - memset(&stream, 0, sizeof(stream));
1176 git_deflate_init(&stream, zlib_compression_level);
1177 stream.next_in = in;
1178 stream.avail_in = size;
builtin/pack-objects.c
-2
@@ -123,7 +123,6 @@ static unsigned long do_compress(void **pptr, unsigned long size)
123 void *in, *out;
124 unsigned long maxsize;
125
126 - memset(&stream, 0, sizeof(stream));
126 git_deflate_init(&stream, pack_compression_level);
127 maxsize = git_deflate_bound(&stream, size);
128
@@ -151,7 +150,6 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fi
150 unsigned char obuf[1024 * 16];
151 unsigned long olen = 0;
152
154 - memset(&stream, 0, sizeof(stream));
153 git_deflate_init(&stream, pack_compression_level);
154
155 for (;;) {
bulk-checkin.c
-1
@@ -104,7 +104,6 @@ static int stream_to_pack(struct bulk_checkin_state *state,
104 int write_object = (flags & HASH_WRITE_OBJECT);
105 off_t offset = 0;
106
107 - memset(&s, 0, sizeof(s));
107 git_deflate_init(&s, pack_compression_level);
108
109 hdrlen = encode_in_pack_object_header(type, size, obuf);
diff.c
-1
@@ -2091,7 +2091,6 @@ static unsigned char *deflate_it(char *data,
2091 unsigned char *deflated;
2092 git_zstream stream;
2093
2094 - memset(&stream, 0, sizeof(stream));
2094 git_deflate_init(&stream, zlib_compression_level);
2095 bound = git_deflate_bound(&stream, size);
2096 deflated = xmalloc(bound);
fast-import.c
-3
@@ -1053,7 +1053,6 @@ static int store_object(
1053 } else
1054 delta = NULL;
1055
1056 - memset(&s, 0, sizeof(s));
1056 git_deflate_init(&s, pack_compression_level);
1057 if (delta) {
1058 s.next_in = delta;
@@ -1081,7 +1080,6 @@ static int store_object(
1080 free(delta);
1081 delta = NULL;
1082
1084 - memset(&s, 0, sizeof(s));
1083 git_deflate_init(&s, pack_compression_level);
1084 s.next_in = (void *)dat->buf;
1085 s.avail_in = dat->len;
@@ -1181,7 +1179,6 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
1179
1180 crc32_begin(pack_file);
1181
1184 - memset(&s, 0, sizeof(s));
1182 git_deflate_init(&s, pack_compression_level);
1183
1184 hdrlen = encode_in_pack_object_header(OBJ_BLOB, len, out_buf);
http-push.c
-1
@@ -365,7 +365,6 @@ static void start_put(struct transfer_request *request)
365 hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
366
367 /* Set it up */
368 - memset(&stream, 0, sizeof(stream));
368 git_deflate_init(&stream, zlib_compression_level);
369 size = git_deflate_bound(&stream, len + hdrlen);
370 strbuf_init(&request->buffer.buf, size);
remote-curl.c
-1
@@ -555,7 +555,6 @@ retry:
555 git_zstream stream;
556 int ret;
557
558 - memset(&stream, 0, sizeof(stream));
558 git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
559 gzip_size = git_deflate_bound(&stream, rpc->len);
560 gzip_body = xmalloc(gzip_size);
sha1_file.c
-1
@@ -2916,7 +2916,6 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
2916 }
2917
2918 /* Set it up */
2919 - memset(&stream, 0, sizeof(stream));
2919 git_deflate_init(&stream, zlib_compression_level);
2920 stream.next_out = compressed;
2921 stream.avail_out = sizeof(compressed);
zlib.c
+2
@@ -159,6 +159,7 @@ void git_deflate_init(git_zstream *strm, int level)
159 {
160 int status;
161
162 + memset(strm, 0, sizeof(*strm));
163 zlib_pre_call(strm);
164 status = deflateInit(&strm->z, level);
165 zlib_post_call(strm);
@@ -172,6 +173,7 @@ static void do_git_deflate_init(git_zstream *strm, int level, int windowBits)
173 {
174 int status;
175
176 + memset(strm, 0, sizeof(*strm));
177 zlib_pre_call(strm);
178 status = deflateInit2(&strm->z, level,
179 Z_DEFLATED, windowBits,