From f1d4c3962215160db53683905798ca22a0bfc5ab Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 14 Feb 2015 01:11:10 +0100 Subject: [PATCH] Fixed memory corruption (undefined behaviour) #303 --- glm/detail/type_vec1.hpp | 3 ++ glm/detail/type_vec1.inl | 12 +++++ glm/detail/type_vec2.hpp | 3 ++ glm/detail/type_vec2.inl | 101 +++++++++++++++++++-------------------- glm/detail/type_vec3.hpp | 3 ++ glm/detail/type_vec3.inl | 14 ++++++ glm/detail/type_vec4.hpp | 3 ++ readme.txt | 1 + 8 files changed, 87 insertions(+), 53 deletions(-) diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index 6967d3e0..3550d032 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -108,6 +108,7 @@ namespace glm // Implicit basic constructors GLM_FUNC_DECL tvec1(); + GLM_FUNC_DECL tvec1(tvec1 const & v); template GLM_FUNC_DECL tvec1(tvec1 const & v); @@ -154,6 +155,8 @@ namespace glm ////////////////////////////////////// // Unary arithmetic operators + GLM_FUNC_DECL tvec1 & operator=(tvec1 const & v); + template GLM_FUNC_DECL tvec1 & operator=(tvec1 const & v); template diff --git a/glm/detail/type_vec1.inl b/glm/detail/type_vec1.inl index 16f9ba15..bd756cd4 100644 --- a/glm/detail/type_vec1.inl +++ b/glm/detail/type_vec1.inl @@ -42,6 +42,11 @@ namespace glm # endif {} + template + GLM_FUNC_QUALIFIER tvec1::tvec1(tvec1 const & v) + : x(v.x) + {} + template template GLM_FUNC_QUALIFIER tvec1::tvec1(tvec1 const & v) @@ -135,6 +140,13 @@ namespace glm ////////////////////////////////////// // Unary arithmetic operators + template + GLM_FUNC_QUALIFIER tvec1 & tvec1::operator=(tvec1 const & v) + { + this->x = v.x; + return *this; + } + template template GLM_FUNC_QUALIFIER tvec1 & tvec1::operator=(tvec1 const & v) diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 8663f24e..15fe74e0 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -109,6 +109,7 @@ namespace glm // Implicit basic constructors GLM_FUNC_DECL tvec2(); + GLM_FUNC_DECL tvec2(tvec2 const & v); template GLM_FUNC_DECL tvec2(tvec2 const & v); @@ -162,6 +163,8 @@ namespace glm ////////////////////////////////////// // Unary arithmetic operators + GLM_FUNC_DECL tvec2 & operator=(tvec2 const & v); + template GLM_FUNC_DECL tvec2 & operator=(tvec2 const & v); template diff --git a/glm/detail/type_vec2.inl b/glm/detail/type_vec2.inl index f0219c8f..4db29479 100644 --- a/glm/detail/type_vec2.inl +++ b/glm/detail/type_vec2.inl @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////////// /// OpenGL Mathematics (glm.g-truc.net) /// -/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) +/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to deal /// in the Software without restriction, including without limitation the rights @@ -12,10 +12,6 @@ /// The above copyright notice and this permission notice shall be included in /// all copies or substantial portions of the Software. /// -/// Restrictions: -/// By making use of the Software for military purposes, you choose to make -/// a Bunny unhappy. -/// /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,13 +21,44 @@ /// THE SOFTWARE. /// /// @ref core -/// @file glm/detail/type_tvec2.inl +/// @file glm/core/type_tvec2.inl /// @date 2008-08-18 / 2011-06-15 /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// namespace glm { +#ifdef GLM_FORCE_SIZE_FUNC + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR size_t tvec2::size() const + { + return 2; + } +#else + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tvec2::length() const + { + return 2; + } +#endif + + ////////////////////////////////////// + // Accesses + + template + GLM_FUNC_QUALIFIER T & tvec2::operator[](length_t i) + { + assert(i >= 0 && static_cast(i) < detail::component_count(*this)); + return (&x)[i]; + } + + template + GLM_FUNC_QUALIFIER T const & tvec2::operator[](length_t i) const + { + assert(i >= 0 && static_cast(i) < detail::component_count(*this)); + return (&x)[i]; + } + ////////////////////////////////////// // Implicit basic constructors @@ -42,6 +69,11 @@ namespace glm # endif {} + template + GLM_FUNC_QUALIFIER tvec2::tvec2(tvec2 const & v) + : x(v.x), y(v.y) + {} + template template GLM_FUNC_QUALIFIER tvec2::tvec2(tvec2 const & v) @@ -61,8 +93,8 @@ namespace glm {} template - GLM_FUNC_QUALIFIER tvec2::tvec2(T const & a, T const & b) - : x(a), y(b) + GLM_FUNC_QUALIFIER tvec2::tvec2(T const & s1, T const & s2) + : x(s1), y(s2) {} ////////////////////////////////////// @@ -106,54 +138,17 @@ namespace glm , y(static_cast(v.y)) {} - ////////////////////////////////////// - // Component accesses - -# ifdef GLM_FORCE_SIZE_FUNC - template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2::size_type tvec2::size() const - { - return 2; - } - - template - GLM_FUNC_QUALIFIER T & tvec2::operator[](typename tvec2::size_type i) - { - assert(i >= 0 && static_cast(i) < detail::component_count(*this)); - return (&x)[i]; - } - - template - GLM_FUNC_QUALIFIER T const & tvec2::operator[](typename tvec2::size_type i) const - { - assert(i >= 0 && static_cast(i) < detail::component_count(*this)); - return (&x)[i]; - } -# else - template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2::length_type tvec2::length() const - { - return 2; - } - - template - GLM_FUNC_QUALIFIER T & tvec2::operator[](typename tvec2::length_type i) - { - assert(i >= 0 && static_cast(i) < detail::component_count(*this)); - return (&x)[i]; - } - - template - GLM_FUNC_QUALIFIER T const & tvec2::operator[](typename tvec2::length_type i) const - { - assert(i >= 0 && static_cast(i) < detail::component_count(*this)); - return (&x)[i]; - } -# endif//GLM_FORCE_SIZE_FUNC - ////////////////////////////////////// // Unary arithmetic operators + template + GLM_FUNC_QUALIFIER tvec2 & tvec2::operator=(tvec2 const & v) + { + this->x = v.x; + this->y = v.y; + return *this; + } + template template GLM_FUNC_QUALIFIER tvec2 & tvec2::operator=(tvec2 const & v) diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 5fe349e6..5f0673bf 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -110,6 +110,7 @@ namespace glm // Implicit basic constructors GLM_FUNC_DECL tvec3(); + GLM_FUNC_DECL tvec3(tvec3 const & v); template GLM_FUNC_DECL tvec3(tvec3 const & v); @@ -184,6 +185,8 @@ namespace glm ////////////////////////////////////// // Unary arithmetic operators + GLM_FUNC_DECL tvec3 & operator=(tvec3 const & v); + template GLM_FUNC_DECL tvec3 & operator=(tvec3 const & v); template diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index 92f78436..b2088d8b 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -42,6 +42,11 @@ namespace glm # endif {} + template + GLM_FUNC_QUALIFIER tvec3::tvec3(tvec3 const & v) + : x(v.x), y(v.y), z(v.z) + {} + template template GLM_FUNC_QUALIFIER tvec3::tvec3(tvec3 const & v) @@ -183,6 +188,15 @@ namespace glm ////////////////////////////////////// // Unary arithmetic operators + template + GLM_FUNC_QUALIFIER tvec3& tvec3::operator=(tvec3 const & v) + { + this->x = v.x; + this->y = v.y; + this->z = v.z; + return *this; + } + template template GLM_FUNC_QUALIFIER tvec3& tvec3::operator=(tvec3 const & v) diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index ea9409ab..408d2de4 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -167,6 +167,7 @@ namespace detail // Implicit basic constructors GLM_FUNC_DECL tvec4(); + //GLM_FUNC_DECL tvec4(tvec4 const & v); template GLM_FUNC_DECL tvec4(tvec4 const & v); @@ -284,6 +285,8 @@ namespace detail ////////////////////////////////////// // Unary arithmetic operators + //GLM_FUNC_DECL tvec4 & operator=(tvec4 const & v); + template GLM_FUNC_DECL tvec4 & operator=(tvec4 const & v); template diff --git a/readme.txt b/readme.txt index 7ca5bf76..cb5d6273 100644 --- a/readme.txt +++ b/readme.txt @@ -87,6 +87,7 @@ Fixes: - Disabled GTX_scalar_multiplication for GCC, failing to build tests #242 - Fixed Visual C++ 2015 constexpr errors: Disabled only partial support - Fixed functions not inlined with Clang #302 +- Fixed memory corruption (undefined behaviour) #303 ================================================================================ GLM 0.9.6.1: 2014-12-10