x86: x86_emulate: address violations of MISRA C Rule 19.1

Rule 19.1 states: "An object shall not be assigned or copied
to an overlapping object". In the function like macro "get_rep_prefix",
one member of a union is assigned the value of another member. Reading from one
member and writing to the other violates the rule, while not causing Undefined
Behavior due to their relative sizes. Instead, use casts combined with exactly
overlapping accesses to address violations.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Signed-off-by: Victor Lira <victorm.lira@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Nicola Vetrini authored and Stefano Stabellini committed 2025-05-09 15:54:31 -07:00
1 parent ad3ac58a9d
commit 8808f9a2af
1 file changed
+3 -3
+3 -3
View File
@@ -527,8 +527,8 @@ static inline void put_loop_count(
if ( !amd_like(ctxt) && mode_64bit() && ad_bytes == 4 ) \
{ \
_regs.r(cx) = 0; \
if ( extend_si ) _regs.r(si) = _regs.esi; \
if ( extend_di ) _regs.r(di) = _regs.edi; \
if ( extend_si ) _regs.r(si) = (uint32_t)_regs.r(si); \
if ( extend_di ) _regs.r(di) = (uint32_t)_regs.r(di); \
} \
goto complete_insn; \
} \
@@ -2029,7 +2029,7 @@ x86_emulate(
switch ( op_bytes )
{
case 2: _regs.ax = (int8_t)_regs.ax; break; /* cbw */
case 4: _regs.r(ax) = (uint32_t)(int16_t)_regs.ax; break; /* cwde */
case 4: _regs.r(ax) = (uint32_t)(int16_t)_regs.r(ax); break; /* cwde */
case 8: _regs.r(ax) = (int32_t)_regs.r(ax); break; /* cdqe */
}
break;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.