1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 16:18:48 -05:00

Allocate the decompression buffer for the --manual option on the heap

instead of the stack.
This commit is contained in:
Dan Fandrich 2008-04-21 23:17:20 +00:00
parent 5825cf9457
commit 7076505c24

View File

@ -120,6 +120,7 @@ HEAD
; ;
if($c) { if($c) {
print <<HEAD print <<HEAD
#include <stdlib.h>
#include <zlib.h> #include <zlib.h>
static const unsigned char hugehelpgz[] = { static const unsigned char hugehelpgz[] = {
/* This mumbo-jumbo is the huge help text compressed with gzip. /* This mumbo-jumbo is the huge help text compressed with gzip.
@ -144,10 +145,11 @@ HEAD
print "\n};\n"; print "\n};\n";
print <<EOF print <<EOF
#define BUF_SIZE 0x10000
/* Decompress and send to stdout a gzip-compressed buffer */ /* Decompress and send to stdout a gzip-compressed buffer */
void hugehelp(void) void hugehelp(void)
{ {
unsigned char buf[0x10000]; unsigned char* buf;
int status,headerlen; int status,headerlen;
z_stream z; z_stream z;
@ -165,17 +167,21 @@ void hugehelp(void)
if (inflateInit2(&z, -MAX_WBITS) != Z_OK) if (inflateInit2(&z, -MAX_WBITS) != Z_OK)
return; return;
while(1) { buf = malloc(BUF_SIZE);
z.avail_out = (int)sizeof(buf); if (buf) {
z.next_out = buf; while(1) {
status = inflate(&z, Z_SYNC_FLUSH); z.avail_out = BUF_SIZE;
if (status == Z_OK || status == Z_STREAM_END) { z.next_out = buf;
fwrite(buf, sizeof(buf) - z.avail_out, 1, stdout); status = inflate(&z, Z_SYNC_FLUSH);
if (status == Z_STREAM_END) if (status == Z_OK || status == Z_STREAM_END) {
break; fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout);
if (status == Z_STREAM_END)
break;
}
else
break; /* Error */
} }
else free(buf);
break; /* Error */
} }
inflateEnd(&z); inflateEnd(&z);
} }