Skip to content

Commit

Permalink
Merge pull request #1539 from riscv-software-src/fix-signed-overflow
Browse files Browse the repository at this point in the history
Fix UB on signed overflow in mulh routine
  • Loading branch information
aswaterman authored Dec 14, 2023
2 parents a729aff + 1cc3a1f commit b98de6f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion riscv/arith.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inline int64_t mulh(int64_t a, int64_t b)
{
int negate = (a < 0) != (b < 0);
uint64_t res = mulhu(a < 0 ? -a : a, b < 0 ? -b : b);
return negate ? ~res + (a * b == 0) : res;
return negate ? ~res + ((uint64_t)a * (uint64_t)b == 0) : res;
}

inline int64_t mulhsu(int64_t a, uint64_t b)
Expand Down

0 comments on commit b98de6f

Please sign in to comment.