]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/unzip.c
Merge commit '515673c08f8718a237e90c2130a1f5294f966d6a'
[xonotic/netradiant.git] / tools / quake3 / common / unzip.c
index 63878e6a534c3b69375d19d0adf64fbcc0669a50..1e2be2be5f121af516f4fb92cce822761eb28ac9 100644 (file)
@@ -1261,7 +1261,8 @@ static int unzlocal_getShort (FILE* fin, uLong *pX)
 {
        short   v;
 
-       fread( &v, sizeof(v), 1, fin );
+       if(fread( &v, sizeof(v), 1, fin ) != 1)
+               return UNZ_EOF;
 
        *pX = __LittleShort( v);
        return UNZ_OK;
@@ -1290,7 +1291,8 @@ static int unzlocal_getLong (FILE *fin, uLong *pX)
 {
        int             v;
 
-       fread( &v, sizeof(v), 1, fin );
+       if(fread( &v, sizeof(v), 1, fin ) != 1)
+               return UNZ_EOF;
 
        *pX = __LittleLong( v);
        return UNZ_OK;
@@ -1635,10 +1637,12 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
 
        /* we check the magic */
        if (err==UNZ_OK)
+       {
                if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
                        err=UNZ_ERRNO;
                else if (uMagic!=0x02014b50)
                        err=UNZ_BADZIPFILE;
+       }
 
        if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
                err=UNZ_ERRNO;
@@ -1715,10 +1719,12 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
                        uSizeRead = extraFieldBufferSize;
 
                if (lSeek!=0)
+               {
                        if (fseek(s->file,lSeek,SEEK_CUR)==0)
                                lSeek=0;
                        else
                                err=UNZ_ERRNO;
+               }
                if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
                        if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
                                err=UNZ_ERRNO;
@@ -1740,10 +1746,12 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
                        uSizeRead = commentBufferSize;
 
                if (lSeek!=0)
+               {
                        if (fseek(s->file,lSeek,SEEK_CUR)==0)
                                lSeek=0;
                        else
                                err=UNZ_ERRNO;
+               }
                if ((file_info.size_file_comment>0) && (commentBufferSize>0))
                        if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
                                err=UNZ_ERRNO;
@@ -1906,10 +1914,12 @@ static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,
 
 
        if (err==UNZ_OK)
+       {
                if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
                        err=UNZ_ERRNO;
                else if (uMagic!=0x04034b50)
                        err=UNZ_BADZIPFILE;
+       }
 
        if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
                err=UNZ_ERRNO;
@@ -3407,7 +3417,7 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf
 
         /* compute minimum size table less than or equal to l bits */
         z = g - w;
-        z = z > (uInt)l ? l : z;        /* table size upper limit */
+        z = z > (uInt)l ? (uInt)l : z;        /* table size upper limit */
         if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
         {                       /* too few codes for k-w bit table */
           f -= a + 1;           /* deduct codes from patterns left */
@@ -3445,7 +3455,10 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf
       /* set up table entry in r */
       r.bits = (Byte)(k - w);
       if (p >= v + n)
+      {
         r.exop = 128 + 64;      /* out of values--invalid code */
+        r.base = 0;
+      }
       else if (*p < s)
       {
         r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */