On Wed, 9 Nov 2022, Oleg Oshmyan via Mingw-w64-public wrote:

When int x == INT_MIN, the behaviour of `-x` is undefined.
This causes a crash when isnan is inlined into code instrumented
for Clang's or GCC's -ftrapv, -fsanitize=signed-integer-overflow,
-fsanitize=undefined or similar.

Instead of mucking about with `int` and `unsigned`,
just use `unsigned` throughout the body of isnan.
For unsigned types, all the same arithmetic can be used,
and it is always well-defined and uses two's complement
for negation, which is exactly the same as these platforms'
signed arithmetic that this code already assumes.

Note that there are some inconsistencies in the code of the various
isnan variants, such as whether integer literals are suffixed with `u`
when promoted to `unsigned int` anyway and whether the "true" return
value is 1 or -1. This patch leaves these inconsistencies intact.

Signed-off-by: Oleg Oshmyan <chor...@inbox.lv>
---
mingw-w64-headers/crt/math.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

Thanks, this looks reasonable to me. I'll include it in some rounds of testing, and I can push it tomorrow or so, if it doesn't turn up any issues.

// Martin



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to