From 94f4f2d501448dcdc7381cb0e0b94d337f0cf6f4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 17 Feb 2010 19:37:44 +0000 Subject: Use manual copy instead of memcpy for array (pseudo-)copy constructor to make it safe for C++ types (copy constructor of elements will be called). Fixes crash when changing ingen polyphony because this copies Arrays of intrusive_ptr. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2460 a436a847-0d15-0410-975c-d299462d15a1 --- raul/Array.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'raul/Array.hpp') diff --git a/raul/Array.hpp b/raul/Array.hpp index 7f11880..1d15dcd 100644 --- a/raul/Array.hpp +++ b/raul/Array.hpp @@ -19,7 +19,8 @@ #define RAUL_ARRAY_HPP #include -#include +#include +#include #include "Deletable.hpp" namespace Raul { @@ -43,17 +44,15 @@ public: Array(size_t size, T initial_value) : _size(size), _top(0), _elems(NULL) { if (size > 0) { _elems = new T[size]; - for (size_t i=0; i < size; ++i) + for (size_t i = 0; i < size; ++i) _elems[i] = initial_value; } } - Array(size_t size, const Array& contents) : _size(size), _top(size+1) { + Array(size_t size, const Array& contents) : _size(size), _top(size + 1) { _elems = new T[size]; - if (size <= contents.size()) - memcpy(_elems, contents._elems, size * sizeof(T)); - else - memcpy(_elems, contents._elems, contents.size() * sizeof(T)); + for (size_t i = 0; i < std::min(size, contents.size()); ++i) + _elems[i] = contents[i]; } ~Array() { @@ -78,7 +77,7 @@ public: _top = 0; _elems = new T[num_elems]; - for (size_t i=0; i < _size; ++i) + for (size_t i = 0; i < _size; ++i) _elems[i] = initial_value; } -- cgit v1.2.1