summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-04-21 13:04:44 -0400
committerSean Bright <sean.bright@gmail.com>2017-04-25 16:24:53 -0500
commit4cb1458245a10cbc6287ea8c2e1205b35a10906b (patch)
treea4d7726c3bbd2c7b204775d588697bc5bbf54e3c /apps
parent64f759c3e8e8c78c4a8890a49caf7ca848a04c89 (diff)
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
Diffstat (limited to 'apps')
-rw-r--r--apps/app_minivm.c14
-rw-r--r--apps/app_voicemail.c14
2 files changed, 14 insertions, 14 deletions
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index 5a017d603..64bee5784 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -856,16 +856,16 @@ static int b64_inbuf(struct b64_baseio *bio, FILE *fi)
if (bio->ateof)
return 0;
- if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE,fi)) <= 0) {
- if (ferror(fi))
- return -1;
-
+ if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE, fi)) != B64_BASEMAXINLINE) {
bio->ateof = 1;
- return 0;
+ if (l == 0) {
+ /* Assume EOF */
+ return 0;
+ }
}
- bio->iolen= l;
- bio->iocp= 0;
+ bio->iolen = l;
+ bio->iocp = 0;
return 1;
}
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index b0185c174..5450ffcfb 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -2730,9 +2730,9 @@ static int imap_store_file(const char *dir, const char *mailboxuser, const char
*(vmu->email) = '\0';
return -1;
}
- if (fread(buf, len, 1, p) < len) {
+ if (fread(buf, 1, len, p) != len) {
if (ferror(p)) {
- ast_log(LOG_ERROR, "Short read while reading in mail file.\n");
+ ast_log(LOG_ERROR, "Error while reading mail file: %s\n");
return -1;
}
}
@@ -4745,12 +4745,12 @@ static int inbuf(struct baseio *bio, FILE *fi)
if (bio->ateof)
return 0;
- if ((l = fread(bio->iobuf, 1, BASEMAXINLINE, fi)) <= 0) {
- if (ferror(fi))
- return -1;
-
+ if ((l = fread(bio->iobuf, 1, BASEMAXINLINE, fi)) != BASEMAXINLINE) {
bio->ateof = 1;
- return 0;
+ if (l == 0) {
+ /* Assume EOF */
+ return 0;
+ }
}
bio->iolen = l;