From: divverent Date: Wed, 2 Sep 2009 13:08:52 +0000 (+0000) Subject: do not crash when zlib is missing, but instead do not use deflate/inflate X-Git-Tag: xonotic-v0.1.0preview~1476 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f2a40f08af5c0f24b5af4251e0a265675d7b6ad3;p=xonotic%2Fdarkplaces.git do not crash when zlib is missing, but instead do not use deflate/inflate git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9156 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_parse.c b/cl_parse.c index bee2cb53..ce231f0d 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -1299,9 +1299,18 @@ void CL_StopDownload(int size, int crc) size_t inflated_size; out = FS_Inflate(cls.qw_downloadmemory, cls.qw_downloadmemorycursize, &inflated_size, tempmempool); Mem_Free(cls.qw_downloadmemory); - Con_Printf("Inflated download: new size: %u (%g%%)\n", (unsigned)inflated_size, 100.0 - 100.0*(cls.qw_downloadmemorycursize / (float)inflated_size)); - cls.qw_downloadmemory = out; - cls.qw_downloadmemorycursize = inflated_size; + if(out) + { + Con_Printf("Inflated download: new size: %u (%g%%)\n", (unsigned)inflated_size, 100.0 - 100.0*(cls.qw_downloadmemorycursize / (float)inflated_size)); + cls.qw_downloadmemory = out; + cls.qw_downloadmemorycursize = inflated_size; + } + else + { + cls.qw_downloadmemory = NULL; + cls.qw_downloadmemorycursize = 0; + Con_Printf("Cannot inflate download, possibly corrupt or zlib not present\n"); + } } if(!cls.qw_downloadmemory) diff --git a/fs.c b/fs.c index 50689362..6d20dea7 100644 --- a/fs.c +++ b/fs.c @@ -3337,6 +3337,10 @@ unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflat unsigned char *out = NULL; unsigned char *tmp; + *deflated_size = 0; + if(!zlib_dll) + return NULL; + memset(&strm, 0, sizeof(strm)); strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -3430,6 +3434,10 @@ unsigned char *FS_Inflate(const unsigned char *data, size_t size, size_t *inflat unsigned int have; sizebuf_t outbuf; + *inflated_size = 0; + if(!zlib_dll) + return NULL; + memset(&outbuf, 0, sizeof(outbuf)); outbuf.data = (unsigned char *) Mem_Alloc(tempmempool, sizeof(tmp)); outbuf.maxsize = sizeof(tmp); diff --git a/sv_main.c b/sv_main.c index 74bef76b..a353b11a 100644 --- a/sv_main.c +++ b/sv_main.c @@ -2283,7 +2283,7 @@ static void SV_Download_f(void) Con_DPrintf("Downloading %s to %s\n", host_client->download_name, host_client->name); - if(host_client->download_deflate) + if(host_client->download_deflate && svs.csqc_progdata_deflated) host_client->download_file = FS_FileFromData(svs.csqc_progdata_deflated, svs.csqc_progsize_deflated, true); else host_client->download_file = FS_FileFromData(svs.csqc_progdata, sv.csqc_progsize, true); @@ -2717,8 +2717,13 @@ void SV_Prepare_CSQC(void) //unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool); svs.csqc_progdata_deflated = FS_Deflate(svs.csqc_progdata, progsize, &deflated_size, -1, sv_mempool); svs.csqc_progsize_deflated = (int)deflated_size; - Con_Printf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize)); - Con_DPrintf("Uncompressed: %u\nCompressed: %u\n", (unsigned)sv.csqc_progsize, (unsigned)svs.csqc_progsize_deflated); + if(svs.csqc_progdata_deflated) + { + Con_Printf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize)); + Con_DPrintf("Uncompressed: %u\nCompressed: %u\n", (unsigned)sv.csqc_progsize, (unsigned)svs.csqc_progsize_deflated); + } + else + Con_Printf("Cannot compress - need zlib for this. Using uncompressed progs only.\n"); } }