diff options
author | David Robillard <d@drobilla.net> | 2010-02-17 19:37:44 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-02-17 19:37:44 +0000 |
commit | 94f4f2d501448dcdc7381cb0e0b94d337f0cf6f4 (patch) | |
tree | a997d8b035e488a9a8d6568871f4f7c48f213641 /raul/Array.hpp | |
parent | 8bd3fad8c96d0b42592ab80a4dfdc115a927fe4c (diff) | |
download | raul-94f4f2d501448dcdc7381cb0e0b94d337f0cf6f4.tar.gz raul-94f4f2d501448dcdc7381cb0e0b94d337f0cf6f4.tar.bz2 raul-94f4f2d501448dcdc7381cb0e0b94d337f0cf6f4.zip |
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<Buffer>.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2460 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/Array.hpp')
-rw-r--r-- | raul/Array.hpp | 15 |
1 files changed, 7 insertions, 8 deletions
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 <cassert> -#include <cstdlib> +#include <cstddef> +#include <algorithm> #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<T>& contents) : _size(size), _top(size+1) { + Array(size_t size, const Array<T>& 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; } |