From 974ba3a08a427443369461cbb1196fa7d5b67c04 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Tue, 14 Mar 2006 17:13:44 +0000 Subject: fixed faulty assertion fixed buggy memory deallocation for AtomListStatic svn path=/trunk/; revision=4706 --- externals/grill/flext/source/flatom.cpp | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'externals/grill/flext/source/flatom.cpp') diff --git a/externals/grill/flext/source/flatom.cpp b/externals/grill/flext/source/flatom.cpp index 9f433222..b8853aca 100644 --- a/externals/grill/flext/source/flatom.cpp +++ b/externals/grill/flext/source/flatom.cpp @@ -61,19 +61,32 @@ void flext::CopyAtoms(int cnt,t_atom *dst,const t_atom *src) void flext::AtomList::Alloc(int sz,int keepix,int keeplen,int keepto) { if(lst) { - if(cnt == sz) return; // no change + if(cnt == sz) { + if(keepix != keepto) { + int c = keeplen >= 0?keeplen:cnt; + FLEXT_ASSERT(c+keepto <= cnt); + FLEXT_ASSERT(c+keepix <= cnt); + CopyAtoms(c,lst+keepto,lst+keepix); + } + + return; // no change + } t_atom *l; if(sz) { l = new t_atom[sz]; - if(keepix >= 0) + if(keepix >= 0) { // keep contents - CopyAtoms(keeplen >= 0?keeplen:(cnt > sz?sz:cnt),l+keepto,lst+keepix); + int c = keeplen >= 0?keeplen:(cnt > sz?sz:cnt); + FLEXT_ASSERT(c+keepto <= sz); + FLEXT_ASSERT(c+keepix <= cnt); + CopyAtoms(c,l+keepto,lst+keepix); + } } else l = NULL; - delete[] lst; + Free(); lst = l,cnt = sz; } else { @@ -122,11 +135,21 @@ flext::AtomListStaticBase::~AtomListStaticBase() { Free(); } void flext::AtomListStaticBase::Alloc(int sz,int keepix,int keeplen,int keepto) { - if(sz < precnt) { + if(sz <= precnt) { + // small enough for pre-allocated space + if(lst != predata && lst) { - if(keepix >= 0) + // currently allocated memory is larger than what we need + + if(keepix >= 0) { // keep contents - CopyAtoms(keeplen >= 0?keeplen:(cnt > sz?sz:cnt),predata+keepto,lst+keepix); + int c = keeplen >= 0?keeplen:(cnt > sz?sz:cnt); + FLEXT_ASSERT(c+keepto <= precnt); + FLEXT_ASSERT(c+keepix <= cnt); + CopyAtoms(c,predata+keepto,lst+keepix); + } + + // free allocated memory AtomList::Free(); } lst = predata,cnt = sz; -- cgit v1.2.1