]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_wav.c
cleaned up the fix for solid water in q1bsp dedicated servers
[xonotic/darkplaces.git] / snd_wav.c
index 9ca7fa95b38ca94ad00b8b09826c78ac23309a9c..b55c36653358524b8dd636f341323c92dfeb41a8 100644 (file)
--- a/snd_wav.c
+++ b/snd_wav.c
@@ -65,7 +65,7 @@ static int GetLittleLong(void)
        return val;
 }
 
-static void FindNextChunk(char *name)
+static void FindNextChunk(const char *name)
 {
        while (1)
        {
@@ -84,6 +84,12 @@ static void FindNextChunk(char *name)
                        data_p = NULL;
                        return;
                }
+               if (data_p + iff_chunk_len > iff_end)
+               {
+                       // truncated chunk!
+                       data_p = NULL;
+                       return;
+               }
                data_p -= 8;
                last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 );
                if (!strncmp((const char *)data_p, name, 4))
@@ -91,7 +97,7 @@ static void FindNextChunk(char *name)
        }
 }
 
-static void FindChunk(char *name)
+static void FindChunk(const char *name)
 {
        last_chunk = iff_data;
        FindNextChunk (name);
@@ -297,10 +303,9 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx)
        //if (info.channels == 2)
        //      Log_Printf("stereosounds.log", "%s\n", sfx->name);
 
-#if BYTE_ORDER != LITTLE_ENDIAN
        // We must convert the WAV data from little endian
        // to the machine endianess before resampling it
-       if (info.width == 2)
+       if (info.width == 2 && mem_bigendian)
        {
                unsigned int len, i;
                short* ptr;
@@ -310,7 +315,6 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx)
                for (i = 0; i < len; i++)
                        ptr[i] = LittleShort (ptr[i]);
        }
-#endif
 
        wav_format.speed = info.rate;
        wav_format.width = info.width;