shithub: sox

Download patch

ref: 6217a8c0415657acef3896a0a1bcc1a0c42a9c0c
parent: 6274a0b66c1a0226a5959af92d37b775f61d4901
author: robs <robs>
date: Tue Mar 17 17:55:51 EDT 2009

[ sox-Bugs-2675504 ] undefined behaviour

--- a/src/mp3.c
+++ b/src/mp3.c
@@ -486,15 +486,12 @@
 {
   priv_t *p = (priv_t *) ft->priv;
   unsigned char mp3buffer[7200];
-  int written;
-  size_t written2;
+  int written = lame_encode_flush(p->gfp, mp3buffer, sizeof(mp3buffer));
 
-  if ((written=lame_encode_flush(p->gfp, mp3buffer, 7200)) <0){
-    lsx_fail_errno(ft,SOX_EOF,"Encoding failed");
-  }
-  else if (lsx_writebuf(ft, mp3buffer, written2 = written) < written2){
-    lsx_fail_errno(ft,SOX_EOF,"File write failed");
-  }
+  if (written < 0)
+    lsx_fail_errno(ft, SOX_EOF, "Encoding failed");
+  else if (lsx_writebuf(ft, mp3buffer, (size_t)written) < (size_t)written)
+    lsx_fail_errno(ft, SOX_EOF, "File write failed");
 
   lame_close(p->gfp);
   return SOX_SUCCESS;