Ben Kallus
January 23, 2024 04:06PM
> Casting NaN to integer is undefined behavior,
> but it is fine in some cases where we do additional checks later.
> For example:
> int64_t i64 = njs_unsafe_cast_double_to_int64(num);
> if (i64 == num) {
> // num is integer
> }

This could be fine, but it's not guaranteed by the standard. For this
reason, I think ignoring UBSan warnings is almost always a bad idea.
You can't know what future compiler optimizations will do; all we can
do is to comply with the standard if we want to ensure that code
continues to work in the future. Whether or not most C programmers
want to admit it, writing C is programming an abstract machine. If the
semantics of this machine get in the way of performance, then the
programmer should resort to assembly rather than rely on behavior that
could change at any time.
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Ignoring UndefinedBehaviorSanitizer warnings where appropriate.

Dmitry Volyntsev 240 January 09, 2024 01:18AM

Re: [njs] Ignoring UndefinedBehaviorSanitizer warnings where appropriate.

Ben Kallus 59 January 23, 2024 04:06PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 310
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready