File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,19 @@ typedef unsigned int uint;
8585# endif
8686#endif
8787
88+ /* Use to suppress harmless UBSAN divide by zero warnings. */
89+ #ifdef __SANITIZE_ADDRESS__
90+ /* Used by GCC, note that there doesn't seem to be a way to check for UBSAN specifically. */
91+ # define HAS_UBSAN
92+ #else
93+ /* Used by CLANG. */
94+ # ifdef __has_feature
95+ # if __has_feature (undefined_behavior_sanitizer )
96+ # define HAS_UBSAN
97+ # endif
98+ # endif
99+ #endif
100+
88101#define SWAP (type , a , b ) { \
89102 type sw_ap; \
90103 sw_ap = (a); \
@@ -628,8 +641,15 @@ static void cubic_from_points_offset_fallback(
628641 * in this case the error values approach divide by zero (infinite)
629642 * so there is no need to be too precise when checking if limits have been exceeded. */
630643
644+ #ifndef HAS_UBSAN
631645 double alpha_l = (dists [0 ] / 0.75 ) / fabs (dot_vnvn (tan_l , a [0 ], dims ));
632646 double alpha_r = (dists [1 ] / 0.75 ) / fabs (dot_vnvn (tan_r , a [1 ], dims ));
647+ #else /* Suppress harmless division by zero warnings. */
648+ const double alpha_l_div = fabs (dot_vnvn (tan_l , a [0 ], dims ));
649+ const double alpha_r_div = fabs (dot_vnvn (tan_r , a [1 ], dims ));
650+ double alpha_l = alpha_l_div > 0.0 ? ((dists [0 ] / 0.75 ) / alpha_l_div ) : INFINITY ;
651+ double alpha_r = alpha_r_div > 0.0 ? ((dists [1 ] / 0.75 ) / alpha_r_div ) : INFINITY ;
652+ #endif /* HAS_UBSAN */
633653
634654
635655 if (!(alpha_l > 0.0 ) || (alpha_l > dists [0 ] + dir_dist )) {
You can’t perform that action at this time.
0 commit comments