[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.31,1.32 file.h,1.12,1.13

Max Horn fingolfin at users.sourceforge.net
Wed May 28 12:04:04 CEST 2003


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

Modified Files:
	file.cpp file.h 
Log Message:
the _encbyte code was evil, because it modified the memory passed to write(); worse, though, it incremented ptr2, which then was later passed to fwrite - hence if used to write something while _encbyte != 0, write() resulted in wrong data being written

Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- file.cpp	28 May 2003 02:06:53 -0000	1.31
+++ file.cpp	28 May 2003 19:03:12 -0000	1.32
@@ -266,9 +266,9 @@
 	return (b << 16) | a;
 }
 
-uint32 File::write(void *ptr, uint32 len) {
-	byte *ptr2 = (byte *)ptr;
-
+uint32 File::write(const void *ptr, uint32 len) {
+	byte *tmp = 0;
+	
 	if (_handle == NULL) {
 		error("File is not open!");
 		return 0;
@@ -281,15 +281,20 @@
 		// Maybe FIXME: while it's efficient to do the encoding here,
 		// it not really nice for a write function to modify its input.
 		// Maybe we should work on a copy here...
-		uint32 t_size = len;
-		do {
-			*ptr2++ ^= _encbyte;
-		} while (--t_size);
+		tmp = (byte *)malloc(len);
+		for (uint32 i = 0; i < len; i ++) {
+			tmp[i] = ((const byte *)ptr)[i] ^ _encbyte;
+		}
+		ptr = tmp;
 	}
 
-	if ((uint32)fwrite(ptr2, 1, len, _handle) != len) {
+	if ((uint32)fwrite(ptr, 1, len, _handle) != len) {
 		clearerr(_handle);
 		_ioFailed = true;
+	}
+
+	if (_encbyte != 0) {
+		free(tmp);
 	}
 
 	return len;

Index: file.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- file.h	6 Mar 2003 21:45:20 -0000	1.12
+++ file.h	28 May 2003 19:03:12 -0000	1.13
@@ -60,7 +60,7 @@
 	uint32 readUint32LE();
 	uint16 readUint16BE();
 	uint32 readUint32BE();
-	uint32 write(void *ptr, uint32 size);
+	uint32 write(const void *ptr, uint32 size);
 	void writeByte(byte value);
 	void writeUint16LE(uint16 value);
 	void writeUint32LE(uint32 value);





More information about the Scummvm-git-logs mailing list