From 172ee701ffbdf22edcd0b5175344ab5e6da40412 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 18 Mar 2009 20:15:27 +0100 Subject: [PATCH] wav: Replace assertion by a proper error message. This assertion can be hit easily by choosing wav as the first filter of the filter chain. --- error.h | 5 ++++- wav_filter.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/error.h b/error.h index 24f2a113..7de3f436 100644 --- a/error.h +++ b/error.h @@ -13,7 +13,6 @@ DEFINE_ERRLIST_OBJECT_ENUM; /* these do not need error handling (yet) */ #define SERVER_ERRORS -#define WAV_FILTER_ERRORS #define TIME_ERRORS #define CLOSE_ON_FORK_ERRORS #define DAEMON_ERRORS @@ -37,6 +36,10 @@ extern const char **para_errlist[]; PARA_ERROR(COMPRESS_SYNTAX, "syntax error in compress filter config"), \ +#define WAV_FILTER_ERRORS \ + PARA_ERROR(WAV_BAD_FC, "invalid filter chain configuration"), \ + + #define FEC_ERRORS \ PARA_ERROR(FEC_BAD_IDX, "invalid index vector"), \ PARA_ERROR(FEC_SINGULAR, "unexpected singular matrix"), \ diff --git a/wav_filter.c b/wav_filter.c index b7329c48..1c0da181 100644 --- a/wav_filter.c +++ b/wav_filter.c @@ -7,6 +7,7 @@ /** \file wav_filter.c A filter that inserts a wave header. */ #include "para.h" +#include "error.h" #include "list.h" #include "sched.h" @@ -31,7 +32,6 @@ static void make_wav_header(unsigned int channels, unsigned int samplerate, int bytespersec = channels * samplerate * BITS / 8; int align = channels * BITS / 8; - assert(channels); PARA_DEBUG_LOG("writing wave header: %d channels, %d KHz\n", channels, samplerate); memset(headbuf, 0, WAV_HEADER_LEN); memcpy(headbuf, "RIFF", 4); @@ -57,6 +57,10 @@ static ssize_t wav_convert(char *inbuf, size_t len, struct filter_node *fn) if (*bof) { if (!len) return 0; + if (!fn->fc->channels || !fn->fc->samplerate) { + PARA_ERROR_LOG("%s\n", para_strerror(E_WAV_BAD_FC)); + return -E_WAV_BAD_FC; + } make_wav_header(fn->fc->channels, fn->fc->samplerate, fn); fn->loaded = WAV_HEADER_LEN; *bof = 0; -- 2.39.2