From e566c4c64cbfae1141bb8619c6f4029fedc68ad6 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Sat, 12 Apr 2008 04:16:37 +0000
Subject: decode: fix unsigned comparision and add some paranoid assertions

git-svn-id: https://svn.musicpd.org/mpd/trunk@7301 09075e82-0dd4-0310-85a5-a0d7c8717e4f
---
 src/decode.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

(limited to 'src')

diff --git a/src/decode.c b/src/decode.c
index 7d292726d..0c4503872 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -79,24 +79,25 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc)
 static unsigned calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af,
 					 float totalTime)
 {
-	long chunks;
+	unsigned chunks;
 
-	if (pc->crossFade <= 0 || pc->crossFade >= totalTime ||
+	if (pc->crossFade == 0 || pc->crossFade >= totalTime ||
 	    !isCurrentAudioFormat(af))
 		return 0;
 
+	assert(pc->crossFade > 0);
+	assert(af->bits > 0);
+	assert(af->channels > 0);
+	assert(af->sampleRate > 0);
+
 	chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
 	chunks = (chunks * pc->crossFade + 0.5);
 
 	assert(buffered_chunks >= buffered_before_play);
-	if (chunks > (buffered_chunks - buffered_before_play)) {
+	if (chunks > (buffered_chunks - buffered_before_play))
 		chunks = buffered_chunks - buffered_before_play;
-	}
-
-	if (chunks < 0)
-		chunks = 0;
 
-	return (unsigned)chunks;
+	return chunks;
 }
 
 static int waitOnDecode(PlayerControl * pc, DecoderControl * dc,
-- 
cgit v1.2.3