diff --git a/data-raw/update-s2.R b/data-raw/update-s2.R index 3b8dc076..4a75ab11 100644 --- a/data-raw/update-s2.R +++ b/data-raw/update-s2.R @@ -81,8 +81,17 @@ print_next <- function() { ) cli::cat_bullet( "Fix zero-length array warnings under -Wpedantic by inserting __extension__ at the beginning ", - "of expressions declaring them (s2region_coverer.h#251, util/gtl/compact_array.h#124)" + "of expressions declaring them (s2region_coverer.h#271)" ) + cli::cat_bullet( + "Fix compact_array zero-length array warning by disabling inline elements on gcc ", + "(util/gtl/compact_array.h#89)" + ) + cli::cat_bullet( + "Fix sanitizer error for compact_array when increasing the size of a zero-length array ", + "by wrapping util/gtl/compact_array.h#396-397 with if (old_capacity > 0) {...}" + ) + cli::cat_bullet("Remove extra semi-colon at s2boolean_operation.h#376") cli::cat_bullet("Remove extra semi-colons because of FROMHOST_TYPE_MAP macro (utils/endian/endian.h#565)") cli::cat_bullet( diff --git a/inst/include/s2/util/gtl/compact_array.h b/inst/include/s2/util/gtl/compact_array.h index 3ec23ae0..95947596 100644 --- a/inst/include/s2/util/gtl/compact_array.h +++ b/inst/include/s2/util/gtl/compact_array.h @@ -86,6 +86,9 @@ class compact_array_base { #endif // Opportunistically consider allowing inlined elements. + // dd: this has to be disabled to pass CRAN checks, since there is a + // (potentially) zero-length array that is not the last element of the class (so + // this can't be silenced using __extension__) #if defined(_LP64) && defined(__GNUC__) && false // With 64-bit pointers, our approach is to form a 16-byte struct: // [5 bytes for size, capacity, is_exponent and is_inlined] @@ -393,6 +396,9 @@ class compact_array_base { value_allocator_type allocator; T* new_ptr = allocator.allocate(capacity()); + // dd: this modification fixes a ASAN/UBSAN error, because + // when old_capacity is 0, Array() is nullptr, which is UB + // for memcpy. if (old_capacity > 0) { memcpy(new_ptr, Array(), old_capacity * sizeof(T)); allocator.deallocate(Array(), old_capacity);