Fix undefined behavior sanitizer warnings in Arrangement_2_iterators #9141
+36
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix UBSan false positives in Arrangement_2 iterators
Fixes #9140
Problem
UBSan reports invalid downcasts in
Arrangement_2_iterators.hwhen castingArr_face*toFace*.The warning is a false positive:
Facedoes inherit fromDFace(which isArr_face), but the sanitizer can't confirm it because the types aren't polymorphic and RTTI isn't available.Solution
Added a
CGAL_NO_SANITIZE_UNDEFINEDmacro (following CGAL's pattern for compiler-specific attributes) and applied it to the iterator methods that trigger the warning:T*(bothI_Filtered_iteratorandI_Filtered_const_iterator)operator=(both iterator types)ptr()(both iterator types)The casts themselves are unchanged (still using
static_cast); we only silence UBSan on these specific safe paths.Also added short comments explaining why the annotation is necessary.
Testing
Verified using the minimal reproduction from #9140 with
-fsanitize=undefined,address -std=c++20— warnings are gone and behavior is unchanged.Release Management