Re: [hatari-devel] undefined behaviour fixes

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Le 06/01/2025 à 19:59, Andreas Grabher a écrit :

diff -ru a/src/cpu/gencpu.c b/src/cpu/gencpu.c
--- a/src/cpu/gencpu.c	2024-05-04 20:10:03
+++ b/src/cpu/gencpu.c	2025-01-06 14:04:13
@@ -9224,7 +9224,7 @@
			if (curi->dmode == Dreg) {
				out("uae_u32 tmp = m68k_dreg(regs, dstreg);\n");
				out("offset &= 0x1f;\n");
-				out("tmp = (tmp << offset) | (tmp >> (32 - offset));\n");
+				out("tmp = (offset > 0 && offset < 32) ? ((tmp << offset) | (tmp >> (32 - offset))) : tmp;\n");

offset is restricted to 0x1f, so it is always < 32, i.e. it should be
sufficient to check for "offset != 0" in above condition. I'd maybe also
rather write it like this:

out("tmp = (tmp << offset)\n");
out("if (offset) tmp |= (tmp >> (32 - offset));\n");

?

Thomas


I agree. I appended a new patch, also including the -fwrapv flag.


Hi

your patch to gencpu / readcpu was merged by Toni and I applied it to Hatari too.

Nicolas



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/