Skip to content

Undefined behavior sanitizer type/casting error #9140

@phillip-keldenich

Description

@phillip-keldenich

Issue Details

Compiling basically any source code using CGAL::Arrangement_2 causes some errors being detected by the undefined behavior sanitizer (at least the one in my compiler); the code seems to be doing unchecked downcasts to a pointer type for which this seems to cause undefined behavior. At runtime, no actual errors occur, but since UB is a fickle source of headaches and nose demons, of course CGAL's code should not rely on this. It is, of course, possible that this may be a fault of the sanitizer itself, but since it is built into the compiler I tend to give it the benefit of the doubt right now.

Source Code

For instance, the following minimalistic example exhibits the behavior.

#include <CGAL/Arrangement_2.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <iostream>

using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using ArrTraits = CGAL::Arr_segment_traits_2<Kernel>;
using Arrangement = CGAL::Arrangement_2<ArrTraits>;

int main() {
  Arrangement arr;
  std::cerr << "Unbounded face is unbounded: " << arr.unbounded_face()->is_unbounded() << std::endl;
  return 0;
}

The full output is:

Unbounded face is unbounded: /path/to/cgal/include/CGAL/Arrangement_2/Arrangement_2_iterators.h:293:9: runtime error: downcast of address 0x60b0000000f0 which does not point to an object of type 'value_type' (aka 'CGAL::Arrangement_on_surface_2<CGAL::Arr_segment_traits_2<CGAL::Epick>, CGAL::Arr_bounded_planar_topology_traits_2<CGAL::Arr_segment_traits_2<CGAL::Epick>, CGAL::Arr_dcel<CGAL::Arr_segment_traits_2<CGAL::Epick>>>>::Face')
0x60b0000000f0: note: object is of type 'CGAL::Arr_face<CGAL::Arr_vertex_base<CGAL::Point_2<CGAL::Epick>>, CGAL::Arr_halfedge_base<CGAL::Arr_segment_2<CGAL::Epick>>, CGAL::Arr_face_base>'
 00 00 00 00  a8 8c 9f 05 01 00 00 00  01 00 00 00 be be be be  00 01 00 00 b0 60 00 00  00 01 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'CGAL::Arr_face<CGAL::Arr_vertex_base<CGAL::Point_2<CGAL::Epick>>, CGAL::Arr_halfedge_base<CGAL::Arr_segment_2<CGAL::Epick>>, CGAL::Arr_face_base>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /path/to/cgal/include/CGAL/Arrangement_2/Arrangement_2_iterators.h:293:9 
/path/to/cgal/include/CGAL/Arrangement_2/Arrangement_2_iterators.h:340:12: runtime error: downcast of address 0x60b0000000f0 which does not point to an object of type 'value_type' (aka 'CGAL::Arrangement_on_surface_2<CGAL::Arr_segment_traits_2<CGAL::Epick>, CGAL::Arr_bounded_planar_topology_traits_2<CGAL::Arr_segment_traits_2<CGAL::Epick>, CGAL::Arr_dcel<CGAL::Arr_segment_traits_2<CGAL::Epick>>>>::Face')
0x60b0000000f0: note: object is of type 'CGAL::Arr_face<CGAL::Arr_vertex_base<CGAL::Point_2<CGAL::Epick>>, CGAL::Arr_halfedge_base<CGAL::Arr_segment_2<CGAL::Epick>>, CGAL::Arr_face_base>'
 00 00 00 00  a8 8c 9f 05 01 00 00 00  01 00 00 00 be be be be  00 01 00 00 b0 60 00 00  00 01 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'CGAL::Arr_face<CGAL::Arr_vertex_base<CGAL::Point_2<CGAL::Epick>>, CGAL::Arr_halfedge_base<CGAL::Arr_segment_2<CGAL::Epick>>, CGAL::Arr_face_base>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /path/to/cgal/include/CGAL/Arrangement_2/Arrangement_2_iterators.h:340:12 
1

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): MacOS
  • Compiler:
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: x86_64-apple-darwin24.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • Release or debug mode: Debug with sanitizers
  • Specific flags used (if any): -O0 -g -fsanitize=undefined,address -std=c++20
  • CGAL version: 6.0.1
  • Boost version: 1.89.0
  • Other libraries versions if used (Eigen, TBB, etc.): probably not applicable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions