ref: 1e9330683a2e1999bb2661789726f0b092f7bf7c
parent: 4540c36d2abd34e621d2bf8764ff6b2ad68a72c7
author: Turo Lamminen <[email protected]>
date: Thu Oct 20 07:25:02 EDT 2022
heretic: Fix signedness problem in P_DamageMobj
--- a/src/heretic/p_inter.c
+++ b/src/heretic/p_inter.c
@@ -1350,7 +1350,12 @@
ang = R_PointToAngle2(inflictor->x, inflictor->y,
target->x, target->y);
//thrust = damage*(FRACUNIT>>3)*100/target->info->mass;
- thrust = damage * (FRACUNIT >> 3) * 150 / target->info->mass;
+ // We do this multiplication in unsigned because it might overflow
+ // and signed overflow is undefined behavior
+ // but then we must cast it back to signed for the division
+ // to match original behavior
+ // unsigned to signed cast is implementation defined behavior at worst
+ thrust = ((int) (damage * (FRACUNIT >> 3) * 150u)) / target->info->mass;
// make fall forwards sometimes
if ((damage < 40) && (damage > target->health)
&& (target->z - inflictor->z > 64 * FRACUNIT) && (P_Random() & 1))