aboutsummaryrefslogtreecommitdiff
path: root/engines/cine/pal.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2009-09-15 00:03:21 +0000
committerJohannes Schickel2009-09-15 00:03:21 +0000
commit4e4074f393acff806bd18cf56eeafc572acceb96 (patch)
tree70ac3bf2637f471ad266c4a8c8ecc7d014e77d39 /engines/cine/pal.cpp
parentbfe153871511d51798d22a18ac090a724e6bd102 (diff)
downloadscummvm-rg350-4e4074f393acff806bd18cf56eeafc572acceb96.tar.gz
scummvm-rg350-4e4074f393acff806bd18cf56eeafc572acceb96.tar.bz2
scummvm-rg350-4e4074f393acff806bd18cf56eeafc572acceb96.zip
Fix valgrind warning inside "saturatedAddColor", when using the same palette object as both source and destination.
svn-id: r44094
Diffstat (limited to 'engines/cine/pal.cpp')
-rw-r--r--engines/cine/pal.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/engines/cine/pal.cpp b/engines/cine/pal.cpp
index 757419ef87..01a7c20d25 100644
--- a/engines/cine/pal.cpp
+++ b/engines/cine/pal.cpp
@@ -214,8 +214,20 @@ Palette &Palette::saturatedAddColor(Palette& output, byte firstIndex, byte lastI
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;
}