Browse Source

Fixed memory corruption (undefined behaviour) #303

Christophe Riccio 10 years ago
parent
commit
f1d4c39622

+ 3 - 0
glm/detail/type_vec1.hpp

@@ -108,6 +108,7 @@ namespace glm
 		// Implicit basic constructors
 		// Implicit basic constructors
 
 
 		GLM_FUNC_DECL tvec1();
 		GLM_FUNC_DECL tvec1();
+		GLM_FUNC_DECL tvec1(tvec1<T, P> const & v);
 		template <precision Q>
 		template <precision Q>
 		GLM_FUNC_DECL tvec1(tvec1<T, Q> const & v);
 		GLM_FUNC_DECL tvec1(tvec1<T, Q> const & v);
 
 
@@ -154,6 +155,8 @@ namespace glm
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Unary arithmetic operators
 		// Unary arithmetic operators
 
 
+		GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v);
+
 		template <typename U> 
 		template <typename U> 
 		GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<U, P> const & v);
 		GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<U, P> const & v);
 		template <typename U> 
 		template <typename U> 

+ 12 - 0
glm/detail/type_vec1.inl

@@ -42,6 +42,11 @@ namespace glm
 #		endif
 #		endif
 	{}
 	{}
 
 
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, P> const & v)
+		: x(v.x)
+	{}
+
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <precision Q>
 	template <precision Q>
 	GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, Q> const & v)
 	GLM_FUNC_QUALIFIER tvec1<T, P>::tvec1(tvec1<T, Q> const & v)
@@ -135,6 +140,13 @@ namespace glm
 	//////////////////////////////////////
 	//////////////////////////////////////
 	// Unary arithmetic operators
 	// Unary arithmetic operators
 
 
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<T, P> const & v)
+	{
+		this->x = v.x;
+		return *this;
+	}
+
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <typename U> 
 	template <typename U> 
 	GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<U, P> const & v)
 	GLM_FUNC_QUALIFIER tvec1<T, P> & tvec1<T, P>::operator=(tvec1<U, P> const & v)

+ 3 - 0
glm/detail/type_vec2.hpp

@@ -109,6 +109,7 @@ namespace glm
 		// Implicit basic constructors
 		// Implicit basic constructors
 
 
 		GLM_FUNC_DECL tvec2();
 		GLM_FUNC_DECL tvec2();
+		GLM_FUNC_DECL tvec2(tvec2<T, P> const & v);
 		template <precision Q>
 		template <precision Q>
 		GLM_FUNC_DECL tvec2(tvec2<T, Q> const & v);
 		GLM_FUNC_DECL tvec2(tvec2<T, Q> const & v);
 
 
@@ -162,6 +163,8 @@ namespace glm
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Unary arithmetic operators
 		// Unary arithmetic operators
 
 
+		GLM_FUNC_DECL tvec2<T, P> & operator=(tvec2<T, P> const & v);
+
 		template <typename U>
 		template <typename U>
 		GLM_FUNC_DECL tvec2<T, P> & operator=(tvec2<U, P> const & v);
 		GLM_FUNC_DECL tvec2<T, P> & operator=(tvec2<U, P> const & v);
 		template <typename U>
 		template <typename U>

+ 48 - 53
glm/detail/type_vec2.inl

@@ -1,7 +1,7 @@
 ///////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////
 /// OpenGL Mathematics (glm.g-truc.net)
 /// 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
 /// Permission is hereby granted, free of charge, to any person obtaining a copy
 /// of this software and associated documentation files (the "Software"), to deal
 /// of this software and associated documentation files (the "Software"), to deal
 /// in the Software without restriction, including without limitation the rights
 /// 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
 /// The above copyright notice and this permission notice shall be included in
 /// all copies or substantial portions of the Software.
 /// 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
 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -25,13 +21,44 @@
 /// THE SOFTWARE.
 /// THE SOFTWARE.
 ///
 ///
 /// @ref core
 /// @ref core
-/// @file glm/detail/type_tvec2.inl
+/// @file glm/core/type_tvec2.inl
 /// @date 2008-08-18 / 2011-06-15
 /// @date 2008-08-18 / 2011-06-15
 /// @author Christophe Riccio
 /// @author Christophe Riccio
 ///////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////
 
 
 namespace glm
 namespace glm
 {
 {
+#ifdef GLM_FORCE_SIZE_FUNC
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR size_t tvec2<T, P>::size() const
+	{
+		return 2;
+	}
+#else
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tvec2<T, P>::length() const
+	{
+		return 2;
+	}
+#endif
+
+	//////////////////////////////////////
+	// Accesses
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](length_t i)
+	{
+		assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
+		return (&x)[i];
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](length_t i) const
+	{
+		assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
+		return (&x)[i];
+	}
+
 	//////////////////////////////////////
 	//////////////////////////////////////
 	// Implicit basic constructors
 	// Implicit basic constructors
 
 
@@ -42,6 +69,11 @@ namespace glm
 #		endif
 #		endif
 	{}
 	{}
 
 
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, P> const & v)
+		: x(v.x), y(v.y)
+	{}
+
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <precision Q>
 	template <precision Q>
 	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, Q> const & v)
 	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(tvec2<T, Q> const & v)
@@ -61,8 +93,8 @@ namespace glm
 	{}
 	{}
 
 
 	template <typename T, precision P>
 	template <typename T, precision P>
-	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(T const & a, T const & b)
-		: x(a), y(b)
+	GLM_FUNC_QUALIFIER tvec2<T, P>::tvec2(T const & s1, T const & s2)
+		: x(s1), y(s2)
 	{}
 	{}
 
 
 	//////////////////////////////////////
 	//////////////////////////////////////
@@ -106,54 +138,17 @@ namespace glm
 		, y(static_cast<T>(v.y))
 		, y(static_cast<T>(v.y))
 	{}
 	{}
 
 
-	//////////////////////////////////////
-	// Component accesses
-
-#	ifdef GLM_FORCE_SIZE_FUNC
-		template <typename T, precision P>
-		GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2<T, P>::size_type tvec2<T, P>::size() const
-		{
-			return 2;
-		}
-
-		template <typename T, precision P>
-		GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](typename tvec2<T, P>::size_type i)
-		{
-			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
-			return (&x)[i];
-		}
-
-		template <typename T, precision P>
-		GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](typename tvec2<T, P>::size_type i) const
-		{
-			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
-			return (&x)[i];
-		}
-#	else
-		template <typename T, precision P>
-		GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename tvec2<T, P>::length_type tvec2<T, P>::length() const
-		{
-			return 2;
-		}
-
-		template <typename T, precision P>
-		GLM_FUNC_QUALIFIER T & tvec2<T, P>::operator[](typename tvec2<T, P>::length_type i)
-		{
-			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
-			return (&x)[i];
-		}
-
-		template <typename T, precision P>
-		GLM_FUNC_QUALIFIER T const & tvec2<T, P>::operator[](typename tvec2<T, P>::length_type i) const
-		{
-			assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
-			return (&x)[i];
-		}
-#	endif//GLM_FORCE_SIZE_FUNC
-
 	//////////////////////////////////////
 	//////////////////////////////////////
 	// Unary arithmetic operators
 	// Unary arithmetic operators
 
 
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<T, P> const & v)
+	{
+		this->x = v.x;
+		this->y = v.y;
+		return *this;
+	}
+
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <typename U>
 	template <typename U>
 	GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<U, P> const & v)
 	GLM_FUNC_QUALIFIER tvec2<T, P> & tvec2<T, P>::operator=(tvec2<U, P> const & v)

+ 3 - 0
glm/detail/type_vec3.hpp

@@ -110,6 +110,7 @@ namespace glm
 		// Implicit basic constructors
 		// Implicit basic constructors
 
 
 		GLM_FUNC_DECL tvec3();
 		GLM_FUNC_DECL tvec3();
+		GLM_FUNC_DECL tvec3(tvec3<T, P> const & v);
 		template <precision Q>
 		template <precision Q>
 		GLM_FUNC_DECL tvec3(tvec3<T, Q> const & v);
 		GLM_FUNC_DECL tvec3(tvec3<T, Q> const & v);
 
 
@@ -184,6 +185,8 @@ namespace glm
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Unary arithmetic operators
 		// Unary arithmetic operators
 
 
+		GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<T, P> const & v);
+
 		template <typename U>
 		template <typename U>
 		GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<U, P> const & v);
 		GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<U, P> const & v);
 		template <typename U>
 		template <typename U>

+ 14 - 0
glm/detail/type_vec3.inl

@@ -42,6 +42,11 @@ namespace glm
 #		endif
 #		endif
 	{}
 	{}
 
 
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, P> const & v)
+		: x(v.x), y(v.y), z(v.z)
+	{}
+
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <precision Q>
 	template <precision Q>
 	GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, Q> const & v)
 	GLM_FUNC_QUALIFIER tvec3<T, P>::tvec3(tvec3<T, Q> const & v)
@@ -183,6 +188,15 @@ namespace glm
 	//////////////////////////////////////
 	//////////////////////////////////////
 	// Unary arithmetic operators
 	// Unary arithmetic operators
 
 
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<T, P> const & v)
+	{
+		this->x = v.x;
+		this->y = v.y;
+		this->z = v.z;
+		return *this;
+	}
+
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <typename U>
 	template <typename U>
 	GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<U, P> const & v)
 	GLM_FUNC_QUALIFIER tvec3<T, P>& tvec3<T, P>::operator=(tvec3<U, P> const & v)

+ 3 - 0
glm/detail/type_vec4.hpp

@@ -167,6 +167,7 @@ namespace detail
 		// Implicit basic constructors
 		// Implicit basic constructors
 
 
 		GLM_FUNC_DECL tvec4();
 		GLM_FUNC_DECL tvec4();
+		//GLM_FUNC_DECL tvec4(tvec4<T, P> const & v);
 		template <precision Q>
 		template <precision Q>
 		GLM_FUNC_DECL tvec4(tvec4<T, Q> const & v);
 		GLM_FUNC_DECL tvec4(tvec4<T, Q> const & v);
 
 
@@ -284,6 +285,8 @@ namespace detail
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Unary arithmetic operators
 		// Unary arithmetic operators
 
 
+		//GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<T, P> const & v);
+
 		template <typename U>
 		template <typename U>
 		GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<U, P> const & v);
 		GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<U, P> const & v);
 		template <typename U>
 		template <typename U>

+ 1 - 0
readme.txt

@@ -87,6 +87,7 @@ Fixes:
 - Disabled GTX_scalar_multiplication for GCC, failing to build tests #242
 - Disabled GTX_scalar_multiplication for GCC, failing to build tests #242
 - Fixed Visual C++ 2015 constexpr errors: Disabled only partial support
 - Fixed Visual C++ 2015 constexpr errors: Disabled only partial support
 - Fixed functions not inlined with Clang #302
 - Fixed functions not inlined with Clang #302
+- Fixed memory corruption (undefined behaviour) #303
 
 
 ================================================================================
 ================================================================================
 GLM 0.9.6.1: 2014-12-10
 GLM 0.9.6.1: 2014-12-10