summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-03-15 02:00:03 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-03-15 02:00:03 +0000
commit92bec5a5a629ac0e82d3ac91a46ff19b78816b52 (patch)
treefe27b1c51e2b73bacccb3333eabf491f1e2ad504 /gfx
parentRemove unused bits from gameMainSelector.cpp (diff)
downloadilt-92bec5a5a629ac0e82d3ac91a46ff19b78816b52.tar.bz2
ilt-92bec5a5a629ac0e82d3ac91a46ff19b78816b52.tar.xz
ilt-92bec5a5a629ac0e82d3ac91a46ff19b78816b52.zip
Avoid UB in calculating member offset
Bit hacky; local dummy var to base a fake pointer on.
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/glVertexArray.h6
1 files 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<typename M, typename T> struct MP {
constexpr MP(M T::* ptr) : ptr {ptr} { }
+ constexpr
operator GLuint() const
{
- return static_cast<GLuint>(reinterpret_cast<const char *>(&(static_cast<T *>(nullptr)->*ptr))
- - static_cast<const char *>(nullptr));
+ constexpr static char dummy {};
+ return static_cast<GLuint>(reinterpret_cast<const char *>(&(reinterpret_cast<const T *>(&dummy)->*ptr))
+ - reinterpret_cast<const char *>(&dummy));
}
M T::* ptr;