[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 5/7] fpu/softfloat: avoid undefined behaviour when normalising
From: |
Alex Bennée |
Subject: |
[PATCH v1 5/7] fpu/softfloat: avoid undefined behaviour when normalising empty sigs |
Date: |
Fri, 27 Mar 2020 09:49:43 +0000 |
The undefined behaviour checker pointed out that a shift of 64 would
lead to undefined behaviour.
Signed-off-by: Alex Bennée <address@hidden>
---
fpu/softfloat.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 301ce3b537b..444d35920dd 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -3834,9 +3834,14 @@ void normalizeFloatx80Subnormal(uint64_t aSig, int32_t
*zExpPtr,
{
int8_t shiftCount;
- shiftCount = clz64(aSig);
- *zSigPtr = aSig<<shiftCount;
- *zExpPtr = 1 - shiftCount;
+ if (aSig) {
+ shiftCount = clz64(aSig);
+ *zSigPtr = aSig << shiftCount;
+ *zExpPtr = 1 - shiftCount;
+ } else {
+ *zSigPtr = 0;
+ *zExpPtr = 1 - 64;
+ }
}
/*----------------------------------------------------------------------------
--
2.20.1
- Re: [PATCH v1 1/7] elf-ops: bail out if we have no function symbols, (continued)
- [PATCH v1 3/7] tests/tcg: remove extraneous pasting macros, Alex Bennée, 2020/03/27
- [PATCH v1 2/7] linux-user: protect fcntl64 with an #ifdef, Alex Bennée, 2020/03/27
- [PATCH v1 4/7] linux-user: more debug for init_guest_space, Alex Bennée, 2020/03/27
- [PATCH v1 6/7] target/xtensa: add FIXME for translation memory leak, Alex Bennée, 2020/03/27
- [PATCH v1 5/7] fpu/softfloat: avoid undefined behaviour when normalising empty sigs,
Alex Bennée <=
- Re: [PATCH v1 5/7] fpu/softfloat: avoid undefined behaviour when normalising empty sigs, Aleksandar Markovic, 2020/03/27
- [PATCH v1 7/7] gdbstub: fix compiler complaining, Alex Bennée, 2020/03/27
- Re: [PATCH for 5.0 v1 0/7] A selection of sanitiser fixes, no-reply, 2020/03/27