1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-27 12:16:10 +02:00

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>
This commit is contained in:
René Scharfe 2015-03-05 23:49:46 +01:00 committed by Junio C Hamano
parent 282616c72d
commit 9a6f1287fb
10 changed files with 2 additions and 13 deletions

View File

@ -120,7 +120,6 @@ static void *zlib_deflate_raw(void *data, unsigned long size,
void *buffer; void *buffer;
int result; int result;
memset(&stream, 0, sizeof(stream));
git_deflate_init_raw(&stream, compression_level); git_deflate_init_raw(&stream, compression_level);
maxsize = git_deflate_bound(&stream, size); maxsize = git_deflate_bound(&stream, size);
buffer = xmalloc(maxsize); buffer = xmalloc(maxsize);
@ -349,7 +348,6 @@ static int write_zip_entry(struct archiver_args *args,
size_t out_len; size_t out_len;
unsigned char compressed[STREAM_BUFFER_SIZE * 2]; unsigned char compressed[STREAM_BUFFER_SIZE * 2];
memset(&zstream, 0, sizeof(zstream));
git_deflate_init_raw(&zstream, args->compression_level); git_deflate_init_raw(&zstream, args->compression_level);
compressed_size = 0; compressed_size = 0;

View File

@ -1173,7 +1173,6 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)
int status; int status;
unsigned char outbuf[4096]; unsigned char outbuf[4096];
memset(&stream, 0, sizeof(stream));
git_deflate_init(&stream, zlib_compression_level); git_deflate_init(&stream, zlib_compression_level);
stream.next_in = in; stream.next_in = in;
stream.avail_in = size; stream.avail_in = size;

View File

@ -123,7 +123,6 @@ static unsigned long do_compress(void **pptr, unsigned long size)
void *in, *out; void *in, *out;
unsigned long maxsize; unsigned long maxsize;
memset(&stream, 0, sizeof(stream));
git_deflate_init(&stream, pack_compression_level); git_deflate_init(&stream, pack_compression_level);
maxsize = git_deflate_bound(&stream, size); maxsize = git_deflate_bound(&stream, size);
@ -151,7 +150,6 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fi
unsigned char obuf[1024 * 16]; unsigned char obuf[1024 * 16];
unsigned long olen = 0; unsigned long olen = 0;
memset(&stream, 0, sizeof(stream));
git_deflate_init(&stream, pack_compression_level); git_deflate_init(&stream, pack_compression_level);
for (;;) { for (;;) {

View File

@ -104,7 +104,6 @@ static int stream_to_pack(struct bulk_checkin_state *state,
int write_object = (flags & HASH_WRITE_OBJECT); int write_object = (flags & HASH_WRITE_OBJECT);
off_t offset = 0; off_t offset = 0;
memset(&s, 0, sizeof(s));
git_deflate_init(&s, pack_compression_level); git_deflate_init(&s, pack_compression_level);
hdrlen = encode_in_pack_object_header(type, size, obuf); hdrlen = encode_in_pack_object_header(type, size, obuf);

1
diff.c
View File

@ -2091,7 +2091,6 @@ static unsigned char *deflate_it(char *data,
unsigned char *deflated; unsigned char *deflated;
git_zstream stream; git_zstream stream;
memset(&stream, 0, sizeof(stream));
git_deflate_init(&stream, zlib_compression_level); git_deflate_init(&stream, zlib_compression_level);
bound = git_deflate_bound(&stream, size); bound = git_deflate_bound(&stream, size);
deflated = xmalloc(bound); deflated = xmalloc(bound);

View File

@ -1053,7 +1053,6 @@ static int store_object(
} else } else
delta = NULL; delta = NULL;
memset(&s, 0, sizeof(s));
git_deflate_init(&s, pack_compression_level); git_deflate_init(&s, pack_compression_level);
if (delta) { if (delta) {
s.next_in = delta; s.next_in = delta;
@ -1081,7 +1080,6 @@ static int store_object(
free(delta); free(delta);
delta = NULL; delta = NULL;
memset(&s, 0, sizeof(s));
git_deflate_init(&s, pack_compression_level); git_deflate_init(&s, pack_compression_level);
s.next_in = (void *)dat->buf; s.next_in = (void *)dat->buf;
s.avail_in = dat->len; s.avail_in = dat->len;
@ -1181,7 +1179,6 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
crc32_begin(pack_file); crc32_begin(pack_file);
memset(&s, 0, sizeof(s));
git_deflate_init(&s, pack_compression_level); git_deflate_init(&s, pack_compression_level);
hdrlen = encode_in_pack_object_header(OBJ_BLOB, len, out_buf); hdrlen = encode_in_pack_object_header(OBJ_BLOB, len, out_buf);

View File

@ -365,7 +365,6 @@ static void start_put(struct transfer_request *request)
hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1; hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
/* Set it up */ /* Set it up */
memset(&stream, 0, sizeof(stream));
git_deflate_init(&stream, zlib_compression_level); git_deflate_init(&stream, zlib_compression_level);
size = git_deflate_bound(&stream, len + hdrlen); size = git_deflate_bound(&stream, len + hdrlen);
strbuf_init(&request->buffer.buf, size); strbuf_init(&request->buffer.buf, size);

View File

@ -555,7 +555,6 @@ static int post_rpc(struct rpc_state *rpc)
git_zstream stream; git_zstream stream;
int ret; int ret;
memset(&stream, 0, sizeof(stream));
git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION); git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
gzip_size = git_deflate_bound(&stream, rpc->len); gzip_size = git_deflate_bound(&stream, rpc->len);
gzip_body = xmalloc(gzip_size); gzip_body = xmalloc(gzip_size);

View File

@ -2916,7 +2916,6 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
} }
/* Set it up */ /* Set it up */
memset(&stream, 0, sizeof(stream));
git_deflate_init(&stream, zlib_compression_level); git_deflate_init(&stream, zlib_compression_level);
stream.next_out = compressed; stream.next_out = compressed;
stream.avail_out = sizeof(compressed); stream.avail_out = sizeof(compressed);

2
zlib.c
View File

@ -159,6 +159,7 @@ void git_deflate_init(git_zstream *strm, int level)
{ {
int status; int status;
memset(strm, 0, sizeof(*strm));
zlib_pre_call(strm); zlib_pre_call(strm);
status = deflateInit(&strm->z, level); status = deflateInit(&strm->z, level);
zlib_post_call(strm); zlib_post_call(strm);
@ -172,6 +173,7 @@ static void do_git_deflate_init(git_zstream *strm, int level, int windowBits)
{ {
int status; int status;
memset(strm, 0, sizeof(*strm));
zlib_pre_call(strm); zlib_pre_call(strm);
status = deflateInit2(&strm->z, level, status = deflateInit2(&strm->z, level,
Z_DEFLATED, windowBits, Z_DEFLATED, windowBits,