From e746ce11899b6ad2ba46643ccc038e758f5912cd Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 29 Oct 2011 18:58:39 +0000 Subject: fixed crasher bug where it wasn't checking whether the arguments were in bounds when set by an inlet, fixes bug #3429877 https://sourceforge.net/tracker/?func=detail&atid=478070&aid=3429877&group_id=55736 svn path=/trunk/externals/smlib/; revision=15680 --- deltas-help.pd | 2 +- deltas.c | 29 +++++++++++++++++------------ prevl-help.pd | 2 +- prevl.c | 27 +++++++++++++++++---------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/deltas-help.pd b/deltas-help.pd index 9034308..89d7ada 100644 --- a/deltas-help.pd +++ b/deltas-help.pd @@ -20,7 +20,7 @@ input and past inputs; #X text 153 137 [deltas a b c]; #X text 120 86 b; #X text 66 87 a; -#X text 152 183 requires b<=c; +#X text 152 183 requires am_lo, x->m_hi, x->m_buffer_size); lo=(int)x->m_lo; hi=(int)x->m_hi; n=hi-lo; - size=x->m_buffer_size; + size=x->m_buffer_size; index=x->m_buffer_index; ap = (t_atom *)getbytes(sizeof(t_atom)*n); app=ap; @@ -114,37 +116,40 @@ static void deltas_set(t_deltas *x, t_float lo, t_float hi, t_float size) if (size<1) { size=1; - post("deltas: size is minimum 1..."); + logpost(x, 2, "[deltas]: minimum size is 1"); } if (hi>size) { - post("deltas: higher bound cannot be higher than the buffer size..."); + logpost(x, 2, "[deltas]: higher bound (%g) cannot be greater than the buffer size (%g)", + hi, size); hi=size; } if (lo<0) { - post("deltas: lower bound cannot be negative..."); + logpost(x, 2, "[deltas]: lower bound cannot be negative"); lo=0; } if (hi<1) { - post("deltas: higher bound cannot be smaller than one..."); + logpost(x, 2, "[deltas]: higher bound cannot be smaller than one"); hi=1; } if (hi<=lo) { - post("deltas: higher bound must be higher than lower bound..."); + logpost(x, 2, "[deltas]: higher bound (%g) must be greater than lower bound (%g)", hi, lo); lo=hi-1.0f; } - freebytes(x->m_buffer, x->m_buffer_size); - x->m_hi=(float)((int)hi); x->m_lo=(float)((int)lo); - x->m_buffer_size=(int)size; - x->m_buffer = (float*)getbytes(sizeof(float)*x->m_buffer_size); - deltas_clear(x); - x->m_buffer_index=0; + if (x->m_buffer_size != size) + { + freebytes(x->m_buffer, x->m_buffer_size); + x->m_buffer_size = (int)size; + x->m_buffer = (float*)getbytes(sizeof(float)*x->m_buffer_size); + deltas_clear(x); + x->m_buffer_index=0; + } } static void *deltas_new(t_float lo, t_float hi, t_float size) diff --git a/prevl-help.pd b/prevl-help.pd index 29991a5..c6edee2 100644 --- a/prevl-help.pd +++ b/prevl-help.pd @@ -12,7 +12,7 @@ #X text 127 79 [deltas a b c]; #X text 94 28 b; #X text 40 29 a; -#X text 126 125 requires b<=c; +#X text 126 125 requires am_lo, x->m_hi, x->m_buffer_size); lo=(int)x->m_lo; hi=(int)x->m_hi; @@ -94,37 +96,42 @@ static void prevl_set(t_prevl *x, t_float lo, t_float hi, t_float size) if (size<1) { size=1; - post("prevl: size is minimum 1..."); + logpost(x, 2, "[prevl] size is minimum 1"); } if (hi>size) { - post("prevl: higher bound cannot be higher than the buffer size..."); + logpost(x, 2, "[prevl] higher bound (%g) cannot be greater than the buffer size (%g)", + hi, size); hi=size; } if (lo<0) { - post("prevl: lower bound cannot be negative..."); + logpost(x, 2, "[prevl] lower bound cannot be negative"); lo=0; } if (hi<1) { - post("prevl: higher bound cannot be smaller than one..."); + logpost(x, 2, "[prevl] higher bound (%g) cannot be smaller than 1", hi); hi=1; } if (hi<=lo) { - post("prevl: higher bound must be higher than lower bound..."); + logpost(x, 2, "[prevl] higher bound (%g) must be greater than lower bound (%g)", + hi, lo); lo=hi-1.0f; } - freebytes(x->m_buffer, x->m_buffer_size); x->m_hi=(float)((int)hi); x->m_lo=(float)((int)lo); - x->m_buffer_size=(int)size; - x->m_buffer = (float*)getbytes(sizeof(float)*x->m_buffer_size); - prevl_clear(x); - x->m_buffer_index=0; + if (x->m_buffer_size != size) + { + x->m_buffer_size=(int)size; + freebytes(x->m_buffer, x->m_buffer_size); + x->m_buffer = (float*)getbytes(sizeof(float)*x->m_buffer_size); + prevl_clear(x); + x->m_buffer_index=0; + } } static void *prevl_new(t_float lo, t_float hi, t_float size) -- cgit v1.2.1