Skip to content

Commit 9a6f128

Browse files
rscharfegitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit 9a6f128

10 files changed

+2
-13
lines changed

archive-zip.c

-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ static void *zlib_deflate_raw(void *data, unsigned long size,
120120
void *buffer;
121121
int result;
122122

123-
memset(&stream, 0, sizeof(stream));
124123
git_deflate_init_raw(&stream, compression_level);
125124
maxsize = git_deflate_bound(&stream, size);
126125
buffer = xmalloc(maxsize);
@@ -349,7 +348,6 @@ static int write_zip_entry(struct archiver_args *args,
349348
size_t out_len;
350349
unsigned char compressed[STREAM_BUFFER_SIZE * 2];
351350

352-
memset(&zstream, 0, sizeof(zstream));
353351
git_deflate_init_raw(&zstream, args->compression_level);
354352

355353
compressed_size = 0;

builtin/index-pack.c

-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,6 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)
11731173
int status;
11741174
unsigned char outbuf[4096];
11751175

1176-
memset(&stream, 0, sizeof(stream));
11771176
git_deflate_init(&stream, zlib_compression_level);
11781177
stream.next_in = in;
11791178
stream.avail_in = size;

builtin/pack-objects.c

-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ static unsigned long do_compress(void **pptr, unsigned long size)
123123
void *in, *out;
124124
unsigned long maxsize;
125125

126-
memset(&stream, 0, sizeof(stream));
127126
git_deflate_init(&stream, pack_compression_level);
128127
maxsize = git_deflate_bound(&stream, size);
129128

@@ -151,7 +150,6 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fi
151150
unsigned char obuf[1024 * 16];
152151
unsigned long olen = 0;
153152

154-
memset(&stream, 0, sizeof(stream));
155153
git_deflate_init(&stream, pack_compression_level);
156154

157155
for (;;) {

bulk-checkin.c

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ static int stream_to_pack(struct bulk_checkin_state *state,
104104
int write_object = (flags & HASH_WRITE_OBJECT);
105105
off_t offset = 0;
106106

107-
memset(&s, 0, sizeof(s));
108107
git_deflate_init(&s, pack_compression_level);
109108

110109
hdrlen = encode_in_pack_object_header(type, size, obuf);

diff.c

-1
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,6 @@ static unsigned char *deflate_it(char *data,
20912091
unsigned char *deflated;
20922092
git_zstream stream;
20932093

2094-
memset(&stream, 0, sizeof(stream));
20952094
git_deflate_init(&stream, zlib_compression_level);
20962095
bound = git_deflate_bound(&stream, size);
20972096
deflated = xmalloc(bound);

fast-import.c

-3
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,6 @@ static int store_object(
10531053
} else
10541054
delta = NULL;
10551055

1056-
memset(&s, 0, sizeof(s));
10571056
git_deflate_init(&s, pack_compression_level);
10581057
if (delta) {
10591058
s.next_in = delta;
@@ -1081,7 +1080,6 @@ static int store_object(
10811080
free(delta);
10821081
delta = NULL;
10831082

1084-
memset(&s, 0, sizeof(s));
10851083
git_deflate_init(&s, pack_compression_level);
10861084
s.next_in = (void *)dat->buf;
10871085
s.avail_in = dat->len;
@@ -1181,7 +1179,6 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
11811179

11821180
crc32_begin(pack_file);
11831181

1184-
memset(&s, 0, sizeof(s));
11851182
git_deflate_init(&s, pack_compression_level);
11861183

11871184
hdrlen = encode_in_pack_object_header(OBJ_BLOB, len, out_buf);

http-push.c

-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ static void start_put(struct transfer_request *request)
365365
hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
366366

367367
/* Set it up */
368-
memset(&stream, 0, sizeof(stream));
369368
git_deflate_init(&stream, zlib_compression_level);
370369
size = git_deflate_bound(&stream, len + hdrlen);
371370
strbuf_init(&request->buffer.buf, size);

remote-curl.c

-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ static int post_rpc(struct rpc_state *rpc)
555555
git_zstream stream;
556556
int ret;
557557

558-
memset(&stream, 0, sizeof(stream));
559558
git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
560559
gzip_size = git_deflate_bound(&stream, rpc->len);
561560
gzip_body = xmalloc(gzip_size);

sha1_file.c

-1
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,6 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
29162916
}
29172917

29182918
/* Set it up */
2919-
memset(&stream, 0, sizeof(stream));
29202919
git_deflate_init(&stream, zlib_compression_level);
29212920
stream.next_out = compressed;
29222921
stream.avail_out = sizeof(compressed);

zlib.c

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void git_deflate_init(git_zstream *strm, int level)
159159
{
160160
int status;
161161

162+
memset(strm, 0, sizeof(*strm));
162163
zlib_pre_call(strm);
163164
status = deflateInit(&strm->z, level);
164165
zlib_post_call(strm);
@@ -172,6 +173,7 @@ static void do_git_deflate_init(git_zstream *strm, int level, int windowBits)
172173
{
173174
int status;
174175

176+
memset(strm, 0, sizeof(*strm));
175177
zlib_pre_call(strm);
176178
status = deflateInit2(&strm->z, level,
177179
Z_DEFLATED, windowBits,

0 commit comments

Comments
 (0)