[Scummvm-cvs-logs] SF.net SVN: scummvm:[44094] scummvm/trunk/engines/cine

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Sep 15 02:03:21 CEST 2009


Revision: 44094
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44094&view=rev
Author:   lordhoto
Date:     2009-09-15 00:03:21 +0000 (Tue, 15 Sep 2009)

Log Message:
-----------
Fix valgrind warning inside "saturatedAddColor", when using the same palette object as both source and destination.

Modified Paths:
--------------
    scummvm/trunk/engines/cine/pal.cpp
    scummvm/trunk/engines/cine/script_fw.cpp

Modified: scummvm/trunk/engines/cine/pal.cpp
===================================================================
--- scummvm/trunk/engines/cine/pal.cpp	2009-09-14 22:34:53 UTC (rev 44093)
+++ scummvm/trunk/engines/cine/pal.cpp	2009-09-15 00:03:21 UTC (rev 44094)
@@ -214,8 +214,20 @@
 	assert(firstIndex < output.colorCount() && lastIndex < output.colorCount());
 	assert(output.colorFormat() == colorFormat());
 
-	for (uint i = firstIndex; i <= lastIndex; i++)
-		output._colors[i] = saturatedAddColor(_colors[i], r, g, b);
+	for (uint i = firstIndex; i <= lastIndex; i++) {
+		// WORKAROUND for a valgrind warning on AMD64:
+		//
+		// The old code read: "output._colors[i] = saturatedAddColor(_colors[i], r, g, b);".
+		//
+		// It seems g++ 4.1.2, 4.3.4 and 4.4.1 do a 8 byte read when passing _colors[i] as parameter,
+		// even though the struct is only 3 bytes, resulting in an invalid read, when accessing indices
+		// 14 and 15 of 16 color palettes.
+		//
+		// To work around this issue, we added an temporary variable, which will have padding so
+		// the 8 byte read (which is done when passing src) is assured to be in a valid memory area.
+		const Color src = _colors[i];
+		output._colors[i] = saturatedAddColor(src, r, g, b);
+	}
 
 	return output;
 }

Modified: scummvm/trunk/engines/cine/script_fw.cpp
===================================================================
--- scummvm/trunk/engines/cine/script_fw.cpp	2009-09-14 22:34:53 UTC (rev 44093)
+++ scummvm/trunk/engines/cine/script_fw.cpp	2009-09-15 00:03:21 UTC (rev 44094)
@@ -1405,14 +1405,14 @@
 
 int FWScript::o1_transformPaletteRange() {
 	byte startColor = getNextByte();
-	byte numColor = getNextByte();
+	byte endColor = getNextByte();
 	int16 r = getNextWord();
 	int16 g = getNextWord();
 	int16 b = getNextWord();
 
-	debugC(5, kCineDebugScript, "Line: %d: transformPaletteRange(from:%d,numIdx:%d,r:%d,g:%d,b:%d)", _line, startColor, numColor, r, g, b);
+	debugC(5, kCineDebugScript, "Line: %d: transformPaletteRange(from:%d,to:%d,r:%d,g:%d,b:%d)", _line, startColor, endColor, r, g, b);
 
-	renderer->transformPalette(startColor, numColor, r, g, b);
+	renderer->transformPalette(startColor, endColor, r, g, b);
 	return 0;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list