]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
do not crash when zlib is missing, but instead do not use deflate/inflate
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 2 Sep 2009 13:08:52 +0000 (13:08 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 2 Sep 2009 13:08:52 +0000 (13:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9156 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
fs.c
sv_main.c

index bee2cb533c4d08efcbca02f4ce858b439c79dcb7..ce231f0d9ee8637236d5fe60dacf18c1aee811f1 100644 (file)
@@ -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 50689362902beea52e488de8e9843bd96cc655a6..6d20dea7ffb4a134af9c945774d3de38558ff6fa 100644 (file)
--- 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);
index 74bef76b39122ed27614da8051b95232812c1200..a353b11a3c2b36a8986f4472322f31715723730a 100644 (file)
--- 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");
        }
 }