sysprog21 / semu

A minimalist RISC-V system emulator capable of running Linux kernel
MIT License
251 stars 47 forks source link

Fix signed integer overflow in RV32M #35

Closed visitorckw closed 10 months ago

visitorckw commented 10 months ago

The current implementation of the mul instruction does not guard against integer overflow, potentially leading to undefined behavior. Cast the operands to int64_t before performing the multiplication to ensure that the result can be accommodated without overflow. The lower 32 bits of the product are then extracted, preserving the correct uint32_t type.

jserv commented 10 months ago

Thank @visitorckw for contributing!