[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.37,1.38

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Thu Jul 3 00:04:15 CEST 2003


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv18254

Modified Files:
	file.cpp 
Log Message:
Made read() return the number of bytes that were actually read, rather than
the number that was requested. A lot of our code obviously assumes this
behaviour, and the MP3 file player depends on it because otherwise, when
reaching the end of the file, it will think it read a full buffer, when in
fact it only got part of it and the rest is the remains from the previous
read.

This would cause a brief note from earlier in the track at the end of the
MI1 chapter one screen. Probably other cases as well.

Of course, this may cause regressions but only - I think - if the code was
buggy to begin with.


Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- file.cpp	27 Jun 2003 05:11:16 -0000	1.37
+++ file.cpp	3 Jul 2003 07:03:18 -0000	1.38
@@ -216,6 +216,7 @@
 
 uint32 File::read(void *ptr, uint32 len) {
 	byte *ptr2 = (byte *)ptr;
+	uint32 real_len;
 
 	if (_handle == NULL) {
 		error("File is not open!");
@@ -225,19 +226,20 @@
 	if (len == 0)
 		return 0;
 
-	if ((uint32)fread(ptr2, 1, len, _handle) != len) {
+	real_len = fread(ptr2, 1, len, _handle);
+	if (real_len < len) {
 		clearerr(_handle);
 		_ioFailed = true;
 	}
 
 	if (_encbyte != 0) {
-		uint32 t_size = len;
+		uint32 t_size = real_len;
 		do {
 			*ptr2++ ^= _encbyte;
 		} while (--t_size);
 	}
 
-	return len;
+	return real_len;
 }
 
 byte File::readByte() {





More information about the Scummvm-git-logs mailing list