iir_filter_copy(): don't copy uninitialised state

If iir_filter_copy() was called on a filter which had no state, it would copy
the uninitialised memory from that filter. Check for this.
This commit is contained in:
Laurence Withers 2011-04-15 17:55:53 +00:00
parent 9a87889dd3
commit bc383a92da
1 changed files with 3 additions and 2 deletions

View File

@ -149,7 +149,8 @@ iir_filter_chain(struct iir_filter_t* fi, const struct iir_coeff_t* coeff)
/* iir_filter_copy()
* Performs a deep copy of a filter instance chain.
*/
struct iir_filter_t* iir_filter_copy(const struct iir_filter_t* fi, int state)
struct iir_filter_t*
iir_filter_copy(const struct iir_filter_t* fi, int state)
{
struct iir_filter_t* head = 0, * tail = 0, * copy;
@ -165,7 +166,7 @@ struct iir_filter_t* iir_filter_copy(const struct iir_filter_t* fi, int state)
memcpy(copy->c, fi->c, sizeof(double) * fi->nc);
memcpy(copy->d, fi->d, sizeof(double) * fi->nd);
if(state) {
if(state && fi->ready) {
copy->ready = 1;
memcpy(copy->x, fi->x, sizeof(double) * fi->nc);
memcpy(copy->y, fi->y, sizeof(double) * fi->nd);