shithub: choc

Download patch

ref: 3e9ca5f3aadcfb0416ff5bc80f726ee78af37bc1
parent: 97d07090a9ce9b6b68de724aaa29a90983e3a24f
parent: 8f9f2083e31c795c5982a0472b8f7a7f90ccd334
author: Turo Lamminen <[email protected]>
date: Wed Oct 26 08:01:47 EDT 2022

Merge pull request #1525 from turol/cppcheck-upgrade

Bump cppcheck action to run on Ubuntu 20.04

--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -39,7 +39,7 @@
         run: $GITHUB_WORKSPACE/.travis.sh
 
   cppcheck:
-    runs-on: ubuntu-18.04
+    runs-on: ubuntu-20.04
 
     steps:
       - name: Install dependencies
--- a/.travis.sh
+++ b/.travis.sh
@@ -1,6 +1,7 @@
 #!/bin/sh
 if [ "$ANALYZE" = "true" ] ; then
-	cppcheck --error-exitcode=1 -j2 -UTESTING -Iopl -Isrc -Isrc/setup opl pcsound src textscreen 2> stderr.txt
+	# -D__GNUC__ is required for cppcheck to know about noreturn functions
+	cppcheck --error-exitcode=1 -j2 -UTESTING -D__GNUC__ -Iopl -Isrc -Isrc/setup opl pcsound src textscreen 2> stderr.txt
 	RET=$?
 	if [ -s stderr.txt ]
 	then
--- 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))