From 92bec5a5a629ac0e82d3ac91a46ff19b78816b52 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Mar 2026 02:00:03 +0000 Subject: Avoid UB in calculating member offset Bit hacky; local dummy var to base a fake pointer on. --- gfx/gl/glVertexArray.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gfx/gl/glVertexArray.h b/gfx/gl/glVertexArray.h index 791f74f..323303c 100644 --- a/gfx/gl/glVertexArray.h +++ b/gfx/gl/glVertexArray.h @@ -11,10 +11,12 @@ namespace Impl { template struct MP { constexpr MP(M T::* ptr) : ptr {ptr} { } + constexpr operator GLuint() const { - return static_cast(reinterpret_cast(&(static_cast(nullptr)->*ptr)) - - static_cast(nullptr)); + constexpr static char dummy {}; + return static_cast(reinterpret_cast(&(reinterpret_cast(&dummy)->*ptr)) + - reinterpret_cast(&dummy)); } M T::* ptr; -- cgit v1.3