Skip to content

Commit f061fa4

Browse files
author
Michal Startek
committed
Bugfix
1 parent 1d4d57c commit f061fa4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/IsoSpec++/fixedEnvelopes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace IsoSpec
2323
{
2424

2525
FixedEnvelope::FixedEnvelope(const FixedEnvelope& other) :
26-
_masses(array_copy<double>(other._masses, other._confs_no)),
27-
_probs(array_copy<double>(other._probs, other._confs_no)),
28-
_confs(array_copy_nptr<int>(other._confs, other._confs_no*other.allDim)),
26+
_masses(array_copy_malloc<double>(other._masses, other._confs_no)),
27+
_probs(array_copy_malloc<double>(other._probs, other._confs_no)),
28+
_confs(array_copy_nptr_malloc<int>(other._confs, other._confs_no*other.allDim)),
2929
_confs_no(other._confs_no),
3030
allDim(other.allDim),
3131
sorted_by_mass(other.sorted_by_mass),

src/IsoSpec++/misc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,31 @@ template <typename T> inline static T* array_copy(const T* A, size_t size)
128128
return ret;
129129
}
130130

131+
template <typename T> inline static T* array_copy_malloc(const T* A, size_t size)
132+
{
133+
T* ret = reinterpret_cast<T*>(malloc(size * sizeof(T)));
134+
if(ret == nullptr)
135+
throw std::bad_alloc();
136+
memcpy(ret, A, size*sizeof(T));
137+
return ret;
138+
}
139+
140+
131141
template <typename T> static T* array_copy_nptr(const T* A, size_t size)
132142
{
133143
if(A == nullptr)
134144
return nullptr;
135145
return array_copy(A, size);
136146
}
137147

148+
template <typename T> static T* array_copy_nptr_malloc(const T* A, size_t size)
149+
{
150+
if(A == nullptr)
151+
return nullptr;
152+
return array_copy_malloc(A, size);
153+
}
154+
155+
138156
template<typename T> void dealloc_table(T* tbl, int dim)
139157
{
140158
for(int i = 0; i < dim; i++)

0 commit comments

Comments
 (0)