]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix FS_Seek for compressed file from PK3
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 24 May 2020 14:18:15 +0000 (14:18 +0000)
committerRudolf Polzer <divVerent@gmail.com>
Fri, 12 Mar 2021 21:23:32 +0000 (13:23 -0800)
From Slava: "Currently FS_Seek works incorrectly with compressed files from PK3 but this issue isn't noticed because in most cases engine is using FS_LoadFile which reads file sequentially without seeking."

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12564 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=79fff8c0583c2b27bc216f718332d12d4623ebbc

fs.c

diff --git a/fs.c b/fs.c
index 87367a77c28ed8a6c61803519a1a6a46033cd2da..44c15abb6083149f32944074158725adb74cd1a0 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -3242,9 +3242,9 @@ int FS_Seek (qfile_t* file, fs_offset_t offset, int whence)
        buffer = (unsigned char *)Mem_Alloc (tempmempool, buffersize);
 
        // Skip all data until we reach the requested offset
-       while (offset > file->position)
+       while (offset > (file->position - file->buff_len + file->buff_ind))
        {
-               fs_offset_t diff = offset - file->position;
+               fs_offset_t diff = offset - (file->position - file->buff_len + file->buff_ind);
                fs_offset_t count, len;
 
                count = (diff > buffersize) ? buffersize : diff;