diff options
author | Max Kellermann <max@musicpd.org> | 2018-08-20 14:23:02 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-08-20 14:23:02 +0200 |
commit | 9d63c8220bc01693691618cd507f8d57434bfac0 (patch) | |
tree | cc80ab990e8044b3b94954c65112e291c3eed242 /src/util | |
parent | edd9d16c840d4c181d2c88daf1dc600a25478417 (diff) |
util/Cast: reverse operands in ContainerAttributeOffset()
The result shall be positive.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Cast.hxx | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/util/Cast.hxx b/src/util/Cast.hxx index d71fb593e..21075f1ce 100644 --- a/src/util/Cast.hxx +++ b/src/util/Cast.hxx @@ -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 |