[njs] Ignoring UndefinedBehaviorSanitizer warnings where appropriate.
Ben Kallus
benjamin.p.kallus.gr at dartmouth.edu
Tue Jan 23 21:03:59 UTC 2024
> 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.
More information about the nginx-devel
mailing list