From f63778cf09ffd05bb3a61c8ff100245d9edfb9ff Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 29 Mar 2024 13:21:50 -0600 Subject: [PATCH] Fix a second place where particles compute the size of a buffer. --- include/deal.II/particles/particle_accessor.h | 5 +++-- source/particles/particle_handler.cc | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/deal.II/particles/particle_accessor.h b/include/deal.II/particles/particle_accessor.h index 447af7832d..8e5af0e47b 100644 --- a/include/deal.II/particles/particle_accessor.h +++ b/include/deal.II/particles/particle_accessor.h @@ -883,8 +883,9 @@ namespace Particles { Assert(state() == IteratorState::valid, ExcInternalError()); - std::size_t size = sizeof(get_id()) + sizeof(get_location()) + - sizeof(get_reference_location()); + std::size_t size = sizeof(get_id()) + + sizeof(double) * spacedim + // get_location() + sizeof(double) * dim; // get_reference_location() if (has_properties()) { diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index e3ba25194c..7280ba15e2 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -2366,7 +2366,19 @@ namespace Particles &(*data_range.begin()) + (data_range.end() - data_range.begin())); while (data < end) - insert_particle(data, cell_to_store_particles); + { + const void *old_data = data; + const auto x = insert_particle(data, cell_to_store_particles); + + // Ensure that the particle read exactly as much data as + // it promised it needs to store its data + const void *new_data = data; + (void)old_data; + (void)new_data; + (void)x; + AssertDimension((const char *)new_data - (const char *)old_data, + x->serialized_size_in_bytes()); + } Assert(data == end, ExcMessage( -- 2.39.5