summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-04-20 15:47:50 +0000
committerrubidium <rubidium@openttd.org>2014-04-20 15:47:50 +0000
commitbbed2ff9563ed102e538b512282b645c1e3ef7b6 (patch)
treecf83a202071dc831a064b14b53595f9e717191bd
parent295076155c65c0eab2ca9250eedcd97128dfa915 (diff)
downloadopenttd-bbed2ff9563ed102e538b512282b645c1e3ef7b6.tar.xz
(svn r26475) -Fix: potentially undefined shifts in NewGRF code
-rw-r--r--src/newgrf.cpp4
-rw-r--r--src/newgrf_spritegroup.cpp6
2 files changed, 5 insertions, 5 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 4485b717a..b567fc4c9 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6736,7 +6736,7 @@ static void ParamSet(ByteReader *buf)
if ((int32)src2 < 0) {
res = src1 >> -(int32)src2;
} else {
- res = src1 << src2;
+ res = src1 << (src2 & 0x1F); // Same behaviour as in EvalAdjustT, mask 'value' to 5 bits, which should behave the same on all architectures.
}
break;
@@ -6744,7 +6744,7 @@ static void ParamSet(ByteReader *buf)
if ((int32)src2 < 0) {
res = (int32)src1 >> -(int32)src2;
} else {
- res = (int32)src1 << src2;
+ res = (int32)src1 << (src2 & 0x1F); // Same behaviour as in EvalAdjustT, mask 'value' to 5 bits, which should behave the same on all architectures.
}
break;
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 59fc70fe4..d6d3c172c 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -228,9 +228,9 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust *adjust, ScopeResolver
case DSGA_OP_ROR: return RotateRight(last_value, value);
case DSGA_OP_SCMP: return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
case DSGA_OP_UCMP: return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
- case DSGA_OP_SHL: return (U)last_value << ((U)value & 0x1F); // mask 'value' to 5 bits, which should behave the same on all architectures.
- case DSGA_OP_SHR: return (U)last_value >> ((U)value & 0x1F);
- case DSGA_OP_SAR: return (S)last_value >> ((U)value & 0x1F);
+ case DSGA_OP_SHL: return (uint32)(U)last_value << ((U)value & 0x1F); // Same behaviour as in ParamSet, mask 'value' to 5 bits, which should behave the same on all architectures.
+ case DSGA_OP_SHR: return (uint32)(U)last_value >> ((U)value & 0x1F);
+ case DSGA_OP_SAR: return (int32)(S)last_value >> ((U)value & 0x1F);
default: return value;
}
}