shithub: sox

Download patch

ref: ccfb7451da3c2245fbe5efa1b4545d06633b16bd
parent: 0cbddf485a6196df8c2cc22ad1e9901908c09270
author: rrt <rrt>
date: Wed Nov 21 10:58:50 EST 2007

Check for errors when reading & writing

--- a/src/misc.c
+++ b/src/misc.c
@@ -115,7 +115,8 @@
  */
 size_t sox_readbuf(sox_format_t * ft, void *buf, sox_size_t len)
 {
-    return fread(buf, 1, len, ft->fp);
+  size_t ret = fread(buf, 1, len, ft->fp);
+  return (ferror(ft->fp) || feof(ft->fp)) ? 0 : ret;
 }
 
 /* Skip input without seeking. */
@@ -146,7 +147,8 @@
 
 size_t sox_writebuf(sox_format_t * ft, void const *buf, sox_size_t len)
 {
-    return fwrite(buf, 1, len, ft->fp);
+  size_t ret = fwrite(buf, 1, len, ft->fp);
+  return (ferror(ft->fp) || feof(ft->fp)) ? 0 : ret;
 }
 
 sox_size_t sox_filelength(sox_format_t * ft)