From 3c5c2ebfc2d651f2f77d0df89cbb58a2068bcad0 Mon Sep 17 00:00:00 2001 From: Andre Date: Tue, 23 May 2006 20:47:31 +0200 Subject: [PATCH] check_wav: return error on premature end of file. --- write.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/write.c b/write.c index dffa5ecd..7e6d47a5 100644 --- a/write.c +++ b/write.c @@ -32,6 +32,7 @@ INIT_WRITE_ERRLISTS; struct check_wav_task { char *buf; size_t *loaded; + int *eof; unsigned channels; unsigned sample_rate; struct task task; @@ -53,8 +54,8 @@ static struct writer_node_group *wng; /** * test if audio buffer contains a valid wave header * - * \return If not, return 0, otherwise, store number of channels and sample rate - * in struct conf and return WAV_HEADER_LEN. + * \return If not, return -E_NO_WAV_HEADER, otherwise, return zero. If + * there is less than WAV_HEADER_LEN bytes awailable, return one. */ static void check_wav_pre_select(struct sched *s, struct task *t) { @@ -62,7 +63,7 @@ static void check_wav_pre_select(struct sched *s, struct task *t) unsigned char *a; if (*cwt->loaded < WAV_HEADER_LEN) { - t->ret = 1; + t->ret = *cwt->eof? -E_PREMATURE_END : 1; return; } a = (unsigned char*)cwt->buf; @@ -149,7 +150,6 @@ static struct writer_node_group *check_args(void) ret = 1; out: if (ret > 0) { - wng->eof = &sit.eof; return wng; } free(wng); @@ -163,6 +163,7 @@ static void idt_error_handler(struct task *t) unregister_task(t); wng->buf = sit.buf; wng->loaded = &sit.loaded; + wng->eof = &sit.eof; ret = wng_open(wng); if (ret < 0) { PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); @@ -225,6 +226,7 @@ int main(int argc, char *argv[]) cwt.task.error_handler = cwt_error_handler; cwt.buf = sit.buf; cwt.loaded = &sit.loaded; + cwt.eof = &sit.eof; cwt.task.flags = PRE_EOF_IS_ERROR; register_task(&cwt.task); -- 2.30.2