From: divverent Date: Tue, 23 Oct 2007 14:36:48 +0000 (+0000) Subject: fix FS_Read when reading size 1 (it segfaulted sometimes then) X-Git-Tag: xonotic-v0.1.0preview~2830 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c7df8736a1173c3dd1f7f30c2b722f102e6e816e;p=xonotic%2Fdarkplaces.git fix FS_Read when reading size 1 (it segfaulted sometimes then) 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 --- diff --git a/fs.c b/fs.c index 40ec10a6..a4d173c4 100644 --- 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;