Skip to content

Commit 225a6f1

Browse files
committed
zlib: wrap deflateBound() too
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55bb5c9 commit 225a6f1

File tree

8 files changed

+17
-10
lines changed

8 files changed

+17
-10
lines changed

archive-zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void *zlib_deflate(void *data, unsigned long size,
9797

9898
memset(&stream, 0, sizeof(stream));
9999
git_deflate_init(&stream, compression_level);
100-
maxsize = deflateBound(&stream, size);
100+
maxsize = git_deflate_bound(&stream, size);
101101
buffer = xmalloc(maxsize);
102102

103103
stream.next_in = data;

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
132132

133133
memset(&stream, 0, sizeof(stream));
134134
git_deflate_init(&stream, pack_compression_level);
135-
maxsize = deflateBound(&stream, size);
135+
maxsize = git_deflate_bound(&stream, size);
136136

137137
in = *pptr;
138138
out = xmalloc(maxsize);

cache.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#endif
1717

1818
#include <zlib.h>
19-
#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
20-
#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
21-
#endif
2219

2320
void git_inflate_init(z_streamp strm);
2421
void git_inflate_init_gzip_only(z_streamp strm);
@@ -30,6 +27,7 @@ void git_deflate_init_gzip(z_streamp strm, int level);
3027
void git_deflate_end(z_streamp strm);
3128
int git_deflate_end_gently(z_streamp strm);
3229
int git_deflate(z_streamp strm, int flush);
30+
unsigned long git_deflate_bound(z_streamp, unsigned long);
3331

3432
#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
3533
#define DTYPE(de) ((de)->d_type)

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ static unsigned char *deflate_it(char *data,
17331733

17341734
memset(&stream, 0, sizeof(stream));
17351735
git_deflate_init(&stream, zlib_compression_level);
1736-
bound = deflateBound(&stream, size);
1736+
bound = git_deflate_bound(&stream, size);
17371737
deflated = xmalloc(bound);
17381738
stream.next_out = deflated;
17391739
stream.avail_out = bound;

fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ static int store_object(
10581058
s.next_in = (void *)dat->buf;
10591059
s.avail_in = dat->len;
10601060
}
1061-
s.avail_out = deflateBound(&s, s.avail_in);
1061+
s.avail_out = git_deflate_bound(&s, s.avail_in);
10621062
s.next_out = out = xmalloc(s.avail_out);
10631063
while (git_deflate(&s, Z_FINISH) == Z_OK)
10641064
; /* nothing */
@@ -1081,7 +1081,7 @@ static int store_object(
10811081
git_deflate_init(&s, pack_compression_level);
10821082
s.next_in = (void *)dat->buf;
10831083
s.avail_in = dat->len;
1084-
s.avail_out = deflateBound(&s, s.avail_in);
1084+
s.avail_out = git_deflate_bound(&s, s.avail_in);
10851085
s.next_out = out = xrealloc(out, s.avail_out);
10861086
while (git_deflate(&s, Z_FINISH) == Z_OK)
10871087
; /* nothing */

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void start_put(struct transfer_request *request)
360360
/* Set it up */
361361
memset(&stream, 0, sizeof(stream));
362362
git_deflate_init(&stream, zlib_compression_level);
363-
size = deflateBound(&stream, len + hdrlen);
363+
size = git_deflate_bound(&stream, len + hdrlen);
364364
strbuf_init(&request->buffer.buf, size);
365365
request->buffer.posn = 0;
366366

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static int post_rpc(struct rpc_state *rpc)
476476

477477
memset(&stream, 0, sizeof(stream));
478478
git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
479-
size = deflateBound(&stream, rpc->len);
479+
size = git_deflate_bound(&stream, rpc->len);
480480
gzip_body = xmalloc(size);
481481

482482
stream.next_in = (unsigned char *)rpc->buf;

zlib.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ int git_inflate(z_streamp strm, int flush)
7878
return status;
7979
}
8080

81+
#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
82+
#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
83+
#endif
84+
85+
unsigned long git_deflate_bound(z_streamp strm, unsigned long size)
86+
{
87+
return deflateBound(strm, size);
88+
}
89+
8190
void git_deflate_init(z_streamp strm, int level)
8291
{
8392
int status = deflateInit(strm, level);

0 commit comments

Comments
 (0)