Commit 9d63c822 authored by Max Kellermann's avatar Max Kellermann

util/Cast: reverse operands in ContainerAttributeOffset()

The result shall be positive.
parent edd9d16c
......@@ -53,7 +53,7 @@ template<class C, class A>
static constexpr inline ptrdiff_t
ContainerAttributeOffset(const C *null_c, const A C::*p)
{
return ptrdiff_t((const char *)null_c - (const char *)&(null_c->*p));
return ptrdiff_t((const char *)&(null_c->*p) - (const char *)null_c);
}
template<class C, class A>
......@@ -70,7 +70,7 @@ template<class C, class A>
static inline constexpr C &
ContainerCast(A &a, const A C::*member)
{
return *OffsetCast<C, A>(&a, ContainerAttributeOffset<C, A>(member));
return *OffsetCast<C, A>(&a, -ContainerAttributeOffset<C, A>(member));
}
/**
......@@ -80,7 +80,7 @@ template<class C, class A>
static inline constexpr const C &
ContainerCast(const A &a, const A C::*member)
{
return *OffsetCast<const C, const A>(&a, ContainerAttributeOffset<C, A>(member));
return *OffsetCast<const C, const A>(&a, -ContainerAttributeOffset<C, A>(member));
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment