]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
fix FS_Read when reading size 1 (it segfaulted sometimes then)
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 23 Oct 2007 14:36:48 +0000 (14:36 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 23 Oct 2007 14:36:48 +0000 (14:36 +0000)
fix FS_Getc to allow 8bit data (by using unsigned char instead, like fgetc)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7651 d7cf8633-e32d-0410-b094-e92efae38249

fs.c

diff --git a/fs.c b/fs.c
index 40ec10a61ee94461039914bbca8505b57824fcf4..a4d173c40233c2b90dde3edebbd9ba44ff4d4b06 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1894,12 +1894,12 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
        if (file->buff_ind < file->buff_len)
        {
                count = file->buff_len - file->buff_ind;
+               count = ((fs_offset_t)buffersize > count) ? count : (fs_offset_t)buffersize;
+               done += count;
+               memcpy (buffer, &file->buff[file->buff_ind], count);
+               file->buff_ind += count;
 
-               done += ((fs_offset_t)buffersize > count) ? count : (fs_offset_t)buffersize;
-               memcpy (buffer, &file->buff[file->buff_ind], done);
-               file->buff_ind += done;
-
-               buffersize -= done;
+               buffersize -= count;
                if (buffersize == 0)
                        return done;
        }
@@ -2111,7 +2111,7 @@ Get the next character of a file
 */
 int FS_Getc (qfile_t* file)
 {
-       char c;
+       unsigned char c;
 
        if (FS_Read (file, &c, 1) != 1)
                return EOF;