|
Boost : |
From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2024-11-16 13:21:10
On Sat, Nov 16, 2024 at 9:18â¯PM Ruben Perez <rubenperez038_at_[hidden]> wrote:
>
> vtable.hpp contains the following piece of code:
>
> auto r = mod.insert(value{argv[1]},
> boost::span<value>{reinterpret_cast<value
> *>(argv + 2),
>
> static_cast<std::size_t>(argc - 2)},
> sqlite3_vtab_on_conflict(db));
>
> Where argv is a sqlite3_value **, and sqlite3::value is a wrapper
> class roughly looking like this:
>
> struct value
> {
> // More member functions
> explicit value(sqlite3_value * value_) noexcept : value_(value_) {}
> private:
> sqlite3_value * value_ = nullptr;
> };
>
> I had the impression that such a cast is UB (although it seems to work
> and seems to be accepted by ubsan). Could someone with more knowledge
> about the language point out whether this is allowed or not (and why)
>
I have a static assert in the code, to make sure this works out.
static_assert(sizeof(value) == sizeof(sqlite3_value*), "value must be
same as sqlite3_value* pointer");
If the struct is aligned to the pointer it should be fine. But it
might technically still be UB, I am not sure either.
> Thanks,
> Ruben.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk