Skip to content

Commit

Permalink
Avoid warnings about comparisons being always true
Browse files Browse the repository at this point in the history
Depending on the signedness of length_t type we may either get
warnings comparison of unsigned expression in ‘>= 0’ being always true
or do insufficient checking by not checking if index is not negative.

Hide the index checking behind a macro that check the index properly.
  • Loading branch information
krnowak authored and christophe-lunarg committed Feb 6, 2024
1 parent 8ebe4b5 commit 38edba1
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 26 deletions.
2 changes: 2 additions & 0 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,10 @@

#ifdef GLM_FORCE_SIZE_T_LENGTH
# define GLM_CONFIG_LENGTH_TYPE GLM_LENGTH_SIZE_T
# define GLM_ASSERT_LENGTH(l, max) (assert ((l) < (max)))
#else
# define GLM_CONFIG_LENGTH_TYPE GLM_LENGTH_INT
# define GLM_ASSERT_LENGTH(l, max) (assert ((l) >= 0 && (l) < (max)))
#endif

namespace glm
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 2, T, Q>::col_type& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 2, T, Q>::col_type const& mat<2, 2, T, Q>::operator[](typename mat<2, 2, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 3, T, Q>::col_type & mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 3, T, Q>::col_type const& mat<2, 3, T, Q>::operator[](typename mat<2, 3, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 4, T, Q>::col_type & mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<2, 4, T, Q>::col_type const& mat<2, 4, T, Q>::operator[](typename mat<2, 4, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 2, T, Q>::col_type & mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 2, T, Q>::col_type const& mat<3, 2, T, Q>::operator[](typename mat<3, 2, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 3, T, Q>::col_type & mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 3, T, Q>::col_type const& mat<3, 3, T, Q>::operator[](typename mat<3, 3, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat3x4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 4, T, Q>::col_type & mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<3, 4, T, Q>::col_type const& mat<3, 4, T, Q>::operator[](typename mat<3, 4, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 2, T, Q>::col_type & mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 2, T, Q>::col_type const& mat<4, 2, T, Q>::operator[](typename mat<4, 2, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 3, T, Q>::col_type & mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 3, T, Q>::col_type const& mat<4, 3, T, Q>::operator[](typename mat<4, 3, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat4x4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,14 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 4, T, Q>::col_type & mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename mat<4, 4, T, Q>::col_type const& mat<4, 4, T, Q>::operator[](typename mat<4, 4, T, Q>::length_type i) const GLM_NOEXCEPT
{
assert(i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
return this->value[i];
}

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_quat.inl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & qua<T, Q>::operator[](typename qua<T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
return (&w)[i];
# else
Expand All @@ -85,7 +85,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& qua<T, Q>::operator[](typename qua<T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
return (&w)[i];
# else
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_vec2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
Expand All @@ -119,7 +119,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_vec3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
Expand All @@ -185,7 +185,7 @@ namespace glm
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_vec4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i)
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
Expand All @@ -496,7 +496,7 @@ namespace detail
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i) const
{
assert(i >= 0 && i < this->length());
GLM_ASSERT_LENGTH(i, this->length());
switch(i)
{
default:
Expand Down

0 comments on commit 38edba1

Please sign in to comment.