From 4acd5b087db2481b89e8956fe245dafd8d7b7df1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 5 Oct 2013 21:03:53 +0200 Subject: [PATCH] Added assert for initilizer lists to match sizes --- glm/core/type_mat2x2.inl | 16 +++++++++------- glm/core/type_mat2x3.inl | 14 ++++++++------ glm/core/type_mat2x4.inl | 14 ++++++++------ glm/core/type_mat3x2.hpp | 4 ++-- glm/core/type_mat3x2.inl | 16 +++++++++------- glm/core/type_mat3x3.inl | 16 +++++++++------- glm/core/type_mat3x4.inl | 16 +++++++++------- glm/core/type_mat4x2.inl | 18 ++++++++++-------- glm/core/type_mat4x3.inl | 18 ++++++++++-------- glm/core/type_mat4x4.inl | 18 ++++++++++-------- test/core/core_type_mat3x2.cpp | 4 ++-- 11 files changed, 86 insertions(+), 68 deletions(-) diff --git a/glm/core/type_mat2x2.inl b/glm/core/type_mat2x2.inl index d6e0aaa0..08e8d645 100644 --- a/glm/core/type_mat2x2.inl +++ b/glm/core/type_mat2x2.inl @@ -144,21 +144,23 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat2x2::tmat2x2(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat2x2::tmat2x2(std::initializer_list l) { - assert(m.size() >= this->length()); - - typename std::initializer_list::iterator p = m.begin(); + assert(l.size() == this->length() * this->value[0].length()); + + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec2(*(p + 0), *(p + 1)); this->value[1] = tvec2(*(p + 2), *(p + 3)); } template - GLM_FUNC_QUALIFIER tmat2x2::tmat2x2(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat2x2::tmat2x2(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat2x3.inl b/glm/core/type_mat2x3.inl index a44ff503..546636f9 100644 --- a/glm/core/type_mat2x3.inl +++ b/glm/core/type_mat2x3.inl @@ -143,21 +143,23 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat2x3::tmat2x3(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat2x3::tmat2x3(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec3(*(p + 0), *(p + 1), *(p + 2)); this->value[1] = tvec3(*(p + 3), *(p + 4), *(p + 5)); } template - GLM_FUNC_QUALIFIER tmat2x3::tmat2x3(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat2x3::tmat2x3(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat2x4.inl b/glm/core/type_mat2x4.inl index 2c2eef18..2551e65d 100644 --- a/glm/core/type_mat2x4.inl +++ b/glm/core/type_mat2x4.inl @@ -146,21 +146,23 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat2x4::tmat2x4(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat2x4::tmat2x4(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec4(*(p + 0), *(p + 1), *(p + 2), *(p + 3)); this->value[1] = tvec4(*(p + 4), *(p + 5), *(p + 6), *(p + 7)); } template - GLM_FUNC_QUALIFIER tmat2x4::tmat2x4(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat2x4::tmat2x4(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat3x2.hpp b/glm/core/type_mat3x2.hpp index 697e353d..a70bea21 100644 --- a/glm/core/type_mat3x2.hpp +++ b/glm/core/type_mat3x2.hpp @@ -80,9 +80,9 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template - GLM_FUNC_DECL tmat3x2(std::initializer_list m); + GLM_FUNC_DECL tmat3x2(std::initializer_list l); - GLM_FUNC_DECL tmat3x2(std::initializer_list > m); + GLM_FUNC_DECL tmat3x2(std::initializer_list > l); #endif//GLM_HAS_INITIALIZER_LISTS ////////////////////////////////////// diff --git a/glm/core/type_mat3x2.inl b/glm/core/type_mat3x2.inl index 4dd063de..7fc38b15 100644 --- a/glm/core/type_mat3x2.inl +++ b/glm/core/type_mat3x2.inl @@ -151,11 +151,11 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat3x2::tmat3x2(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat3x2::tmat3x2(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec2(*(p + 0), *(p + 1)); this->value[1] = tvec2(*(p + 2), *(p + 3)); @@ -163,11 +163,13 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat3x2::tmat3x2(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat3x2::tmat3x2(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; - this->value[2] = m.begin()[2]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; + this->value[2] = l.begin()[2]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat3x3.inl b/glm/core/type_mat3x3.inl index e1b71954..3d4bfc2a 100644 --- a/glm/core/type_mat3x3.inl +++ b/glm/core/type_mat3x3.inl @@ -154,11 +154,11 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat3x3::tmat3x3(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat3x3::tmat3x3(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec3(*(p + 0), *(p + 1), *(p + 2)); this->value[1] = tvec3(*(p + 3), *(p + 4), *(p + 5)); @@ -166,11 +166,13 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat3x3::tmat3x3(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat3x3::tmat3x3(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; - this->value[2] = m.begin()[2]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; + this->value[2] = l.begin()[2]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat3x4.inl b/glm/core/type_mat3x4.inl index a88738f1..50dac71e 100644 --- a/glm/core/type_mat3x4.inl +++ b/glm/core/type_mat3x4.inl @@ -198,11 +198,11 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat3x4::tmat3x4(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat3x4::tmat3x4(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec4(*(p + 0), *(p + 1), *(p + 2), *(p + 3)); this->value[1] = tvec4(*(p + 4), *(p + 5), *(p + 6), *(p + 7)); @@ -210,11 +210,13 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat3x4::tmat3x4(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat3x4::tmat3x4(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; - this->value[2] = m.begin()[2]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; + this->value[2] = l.begin()[2]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat4x2.inl b/glm/core/type_mat4x2.inl index 3ce44c99..d18c1773 100644 --- a/glm/core/type_mat4x2.inl +++ b/glm/core/type_mat4x2.inl @@ -209,11 +209,11 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat4x2::tmat4x2(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat4x2::tmat4x2(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec2(*(p + 0), *(p + 1)); this->value[1] = tvec2(*(p + 2), *(p + 3)); @@ -222,12 +222,14 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat4x2::tmat4x2(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat4x2::tmat4x2(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; - this->value[2] = m.begin()[2]; - this->value[3] = m.begin()[3]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; + this->value[2] = l.begin()[2]; + this->value[3] = l.begin()[3]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat4x3.inl b/glm/core/type_mat4x3.inl index 94636ba4..125354a1 100644 --- a/glm/core/type_mat4x3.inl +++ b/glm/core/type_mat4x3.inl @@ -155,11 +155,11 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat4x3::tmat4x3(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat4x3::tmat4x3(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec3(*(p + 0), *(p + 1), *(p + 2)); this->value[1] = tvec3(*(p + 3), *(p + 4), *(p + 5)); @@ -168,12 +168,14 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat4x3::tmat4x3(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat4x3::tmat4x3(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; - this->value[2] = m.begin()[2]; - this->value[3] = m.begin()[3]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; + this->value[2] = l.begin()[2]; + this->value[3] = l.begin()[3]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/glm/core/type_mat4x4.inl b/glm/core/type_mat4x4.inl index 17e4136d..d1bc35f8 100644 --- a/glm/core/type_mat4x4.inl +++ b/glm/core/type_mat4x4.inl @@ -177,11 +177,11 @@ namespace detail #if(GLM_HAS_INITIALIZER_LISTS) template template - GLM_FUNC_QUALIFIER tmat4x4::tmat4x4(std::initializer_list m) + GLM_FUNC_QUALIFIER tmat4x4::tmat4x4(std::initializer_list l) { - assert(m.size() >= this->length()); + assert(l.size() == this->length() * this->value[0].length()); - typename std::initializer_list::iterator p = m.begin(); + typename std::initializer_list::iterator p = l.begin(); this->value[0] = tvec4(*(p + 0), *(p + 1), *(p + 2), *(p + 3)); this->value[1] = tvec4(*(p + 4), *(p + 5), *(p + 6), *(p + 7)); @@ -190,12 +190,14 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat4x4::tmat4x4(std::initializer_list > m) + GLM_FUNC_QUALIFIER tmat4x4::tmat4x4(std::initializer_list > l) { - this->value[0] = m.begin()[0]; - this->value[1] = m.begin()[1]; - this->value[2] = m.begin()[2]; - this->value[3] = m.begin()[3]; + assert(l.size() == this->length()); + + this->value[0] = l.begin()[0]; + this->value[1] = l.begin()[1]; + this->value[2] = l.begin()[2]; + this->value[3] = l.begin()[3]; } #endif//GLM_HAS_INITIALIZER_LISTS diff --git a/test/core/core_type_mat3x2.cpp b/test/core/core_type_mat3x2.cpp index feb3f1eb..225007d6 100644 --- a/test/core/core_type_mat3x2.cpp +++ b/test/core/core_type_mat3x2.cpp @@ -54,8 +54,8 @@ int test_ctr() Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1; std::vector v1{ - {0, 1, 2, 3, 4, 5, 6, 7, 8}, - {0, 1, 2, 3, 4, 5, 6, 7, 8} + {0, 1, 2, 3, 4, 5}, + {0, 1, 2, 3, 4, 5} }; std::vector v2{