From 2a1dd46bbd14b6fdc6540c76422ac4e9bd8ab724 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 13 Dec 2024 02:31:45 +0100 Subject: [PATCH] Fix address sanitizer warnings with stencil table casting For compatibility, StencilTableReal is cast to StencilTable, which has the same data layout but it's not actually an instance of that class. And so using static_cast is not strictly correct. Use reinterpret_cast instead. --- opensubdiv/far/patchTable.h | 6 +++--- opensubdiv/far/stencilTableFactory.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/opensubdiv/far/patchTable.h b/opensubdiv/far/patchTable.h index d2e9d5a6..6731d788 100644 --- a/opensubdiv/far/patchTable.h +++ b/opensubdiv/far/patchTable.h @@ -777,19 +777,19 @@ PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType() const { inline StencilTable const * PatchTable::GetLocalPointStencilTable() const { assert(LocalPointStencilPrecisionMatchesType()); - return static_cast(_localPointStencils.Get()); + return reinterpret_cast(_localPointStencils.Get()); } inline StencilTable const * PatchTable::GetLocalPointVaryingStencilTable() const { assert(LocalPointVaryingStencilPrecisionMatchesType()); - return static_cast( + return reinterpret_cast( _localPointVaryingStencils.Get()); } inline StencilTable const * PatchTable::GetLocalPointFaceVaryingStencilTable(int channel) const { assert(LocalPointFaceVaryingStencilPrecisionMatchesType()); if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) { - return static_cast( + return reinterpret_cast( _localPointFaceVaryingStencils[channel].Get()); } return NULL; diff --git a/opensubdiv/far/stencilTableFactory.h b/opensubdiv/far/stencilTableFactory.h index c2e95e1c..5b8d43f1 100644 --- a/opensubdiv/far/stencilTableFactory.h +++ b/opensubdiv/far/stencilTableFactory.h @@ -293,14 +293,14 @@ public: static StencilTable const * Create( TopologyRefiner const & refiner, Options options = Options()) { - return static_cast( + return reinterpret_cast( BaseFactory::Create(refiner, options)); } static StencilTable const * Create( int numTables, StencilTable const ** tables) { - return static_cast( + return reinterpret_cast( BaseFactory::Create(numTables, reinterpret_cast(tables))); } @@ -311,7 +311,7 @@ public: StencilTable const *localPointStencilTable, bool factorize = true) { - return static_cast( + return reinterpret_cast( BaseFactory::AppendLocalPointStencilTable(refiner, static_cast(baseStencilTable), static_cast(localPointStencilTable), @@ -324,7 +324,7 @@ public: StencilTable const *localPointStencilTable, bool factorize = true) { - return static_cast( + return reinterpret_cast( BaseFactory::AppendLocalPointStencilTableVarying(refiner, static_cast(baseStencilTable), static_cast(localPointStencilTable), @@ -338,7 +338,7 @@ public: int channel = 0, bool factorize = true) { - return static_cast( + return reinterpret_cast( BaseFactory::AppendLocalPointStencilTableFaceVarying(refiner, static_cast(baseStencilTable), static_cast(localPointStencilTable), @@ -364,7 +364,7 @@ public: PatchTable const * patchTable = 0, Options options = Options()) { - return static_cast( + return reinterpret_cast( BaseFactory::Create( refiner, locationArrays,