Changeset - r21376:6c94a5a545a2
[Not reviewed]
master
0 2 0
rubidium - 10 years ago 2014-04-20 15:47:50
rubidium@openttd.org
(svn r26475) -Fix: potentially undefined shifts in NewGRF code
2 files changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -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;
 

	
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -228,9 +228,9 @@ static U EvalAdjustT(const Deterministic
 
		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;
 
	}
 
}
0 comments (0 inline, 0 general)