From 9d63c8220bc01693691618cd507f8d57434bfac0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Aug 2018 14:23:02 +0200 Subject: [PATCH] util/Cast: reverse operands in ContainerAttributeOffset() The result shall be positive. --- src/util/Cast.hxx | 6 +++--- 1 file 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 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 @@ -70,7 +70,7 @@ template static inline constexpr C & ContainerCast(A &a, const A C::*member) { - return *OffsetCast(&a, ContainerAttributeOffset(member)); + return *OffsetCast(&a, -ContainerAttributeOffset(member)); } /** @@ -80,7 +80,7 @@ template static inline constexpr const C & ContainerCast(const A &a, const A C::*member) { - return *OffsetCast(&a, ContainerAttributeOffset(member)); + return *OffsetCast(&a, -ContainerAttributeOffset(member)); } #endif