Skip to content

Commit bb6348b

Browse files
authored
Similar to previous Vec fixes, fix Color4 UB (#450)
Color4 does not derive from Vec4 the way Color3 derives from Vec3, so UB fix needed to avoid incorrect optimization in the presence of undefined behavior. Signed-off-by: Kimball Thurston <[email protected]>
1 parent cc0d361 commit bb6348b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Imath/ImathColor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,14 @@ template <class T>
513513
IMATH_HOSTDEVICE inline T&
514514
Color4<T>::operator[] (int i) IMATH_NOEXCEPT
515515
{
516-
return (&r)[i];
516+
return reinterpret_cast<T *> (this)[i];
517517
}
518518

519519
template <class T>
520520
IMATH_HOSTDEVICE inline const T&
521521
Color4<T>::operator[] (int i) const IMATH_NOEXCEPT
522522
{
523-
return (&r)[i];
523+
return reinterpret_cast<const T *> (this)[i];
524524
}
525525

526526
template <class T> IMATH_HOSTDEVICE inline Color4<T>::Color4 () IMATH_NOEXCEPT
@@ -624,14 +624,14 @@ template <class T>
624624
IMATH_HOSTDEVICE inline T*
625625
Color4<T>::getValue () IMATH_NOEXCEPT
626626
{
627-
return (T*) &r;
627+
return reinterpret_cast<T*> (this);
628628
}
629629

630630
template <class T>
631631
IMATH_HOSTDEVICE inline const T*
632632
Color4<T>::getValue () const IMATH_NOEXCEPT
633633
{
634-
return (const T*) &r;
634+
return reinterpret_cast<const T*> (this);
635635
}
636636

637637
template <class T>

0 commit comments

Comments
 (0)