From 1b50df78d069632e5607e2937461a33d7f568431 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Fri, 21 Apr 2017 13:04:44 -0400 Subject: cleanup: Fix fread() and fwrite() error handling Cleaned up some of the incorrect uses of fread() and fwrite(), mostly in the format modules. Neither of these functions will ever return a value less than 0, which we were checking for in some cases. I've introduced a fair amount of duplication in the format modules, but I plan to change how format modules work internally in a subsequent patch set, so this is simply a stop-gap. Change-Id: I8ca1cd47c20b2c0b72088bd13b9046f6977aa872 --- addons/format_mp3.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'addons') diff --git a/addons/format_mp3.c b/addons/format_mp3.c index e354148f0..1373f3e92 100644 --- a/addons/format_mp3.c +++ b/addons/format_mp3.c @@ -120,9 +120,11 @@ static int mp3_squeue(struct ast_filestream *s) res = ftell(s->f); p->sbuflen = fread(p->sbuf, 1, MP3_SCACHE, s->f); - if(p->sbuflen < 0) { - ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", p->sbuflen, strerror(errno)); - return -1; + if (p->sbuflen < MP3_SCACHE) { + if (ferror(s->f)) { + ast_log(LOG_WARNING, "Error while reading MP3 file: %s\n", strerror(errno)); + return -1; + } } res = decodeMP3(&p->mp,p->sbuf,p->sbuflen,p->dbuf,MP3_DCACHE,&p->dbuflen); if(res != MP3_OK) -- cgit v1.2.3