aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-10-29 18:58:39 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-10-29 18:58:39 +0000
commite746ce11899b6ad2ba46643ccc038e758f5912cd (patch)
treed69ef1ae4d791c73b8b1d67f58869668830fbaab
parentaaf2905addd68b53986d343e663be734a40d9203 (diff)
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
-rw-r--r--deltas-help.pd2
-rw-r--r--deltas.c29
-rw-r--r--prevl-help.pd2
-rw-r--r--prevl.c27
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 a<b and b<=c;
#X text 152 167 c = buffer size;
#X text 35 50 x(i);
#X msg 79 57 clear;
diff --git a/deltas.c b/deltas.c
index edc3cb0..178d59e 100644
--- a/deltas.c
+++ b/deltas.c
@@ -14,6 +14,7 @@ typedef struct _deltas
float *m_buffer; // circular buffer
} t_deltas;
+static void deltas_set(t_deltas *x, t_float lo, t_float hi, t_float size);
static void deltas_perform_float(t_deltas *x, t_float f)
{
@@ -31,11 +32,12 @@ static void deltas_bang(t_deltas *x)
float last;
float *buffer, *bp;
+ deltas_set(x, x->m_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 a<b and b<=c;
#X text 126 109 c = buffer size;
#X text 9 -8 x(i);
#X obj -14 107 print prevl;
diff --git a/prevl.c b/prevl.c
index 2ba39ce..d43a2df 100644
--- a/prevl.c
+++ b/prevl.c
@@ -14,6 +14,7 @@ typedef struct _prevl
float *m_buffer; // circular buffer
} t_prevl;
+static void prevl_set(t_prevl *x, t_float lo, t_float hi, t_float size);
static void prevl_perform_float(t_prevl *x, t_float f)
{
@@ -30,6 +31,7 @@ static void prevl_bang(t_prevl *x)
t_atom *ap,*app;
float *buffer, *bp;
+ prevl_set(x, x->m_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)