Fix bad pointer arithmetic in aiVector2

Trying to reference 'y' via pointer arithmetic on 'x' is UB
pull/1637/head
Turo Lamminen 2017-12-13 11:28:22 +02:00
parent 45ad63f373
commit 87462165b5
1 changed files with 18 additions and 2 deletions

View File

@ -114,13 +114,29 @@ const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename TReal> template <typename TReal>
TReal aiVector2t<TReal>::operator[](unsigned int i) const { TReal aiVector2t<TReal>::operator[](unsigned int i) const {
return *(&x + i); switch (i) {
case 0:
return x;
case 1:
return y;
default:
break;
}
return x;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename TReal> template <typename TReal>
TReal& aiVector2t<TReal>::operator[](unsigned int i) { TReal& aiVector2t<TReal>::operator[](unsigned int i) {
return *(&x + i); switch (i) {
case 0:
return x;
case 1:
return y;
default:
break;
}
return x;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------