Re: [PATCH 2/4] gdbsupport: add array_view copy function

Tom Tromey
2021-11-16T20:57:31Z

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> An assertion was recently added to array_view::operator[] to ensure we
Simon> don't do out of bounds accesses. However, when the array_view is copied
Simon> to or from using memcpy, it bypasses this safety.

Simon> To address this, add a `copy` free function that copies data from an
Simon> array view to another. It ensures that the destination and source array
Simon> views have the same size and element size, which prevents any kind of
Simon> overflow in the source and in the destination.

In C++20 I think we could use std::copy by having the array view
iterators implement the contiguous_iterator concept. So, maybe a
comment to this effect would be good.

Though maybe in C++20 we would want to switch from array_view to
std::span.

Tom