don't try to read 0 bytes if we hit the icy block (fixes #124) (#125)

* don't try to read 0 bytes if we hit the icy block

* make sure size isn't negative
This commit is contained in:
h3ndrik authored and Earle F. Philhower, III committed 2019-04-12 16:21:00 -07:00
1 parent 87fbcadd80
commit 2c5ae5d490
1 file changed
+12 -7
+12 -7
View File
@@ -164,13 +164,17 @@ retry:
// If the read would hit an ICY block, split it up...
if (((int)(icyByteCount + len) > (int)icyMetaInt) && (icyMetaInt > 0)) {
int beforeIcy = icyMetaInt - icyByteCount;
int ret = stream->read(reinterpret_cast<uint8_t*>(data), beforeIcy);
read += ret;
pos += ret;
len -= ret;
data = (void *)(reinterpret_cast<char*>(data) + ret);
icyByteCount += ret;
if (ret != beforeIcy) return read; // Partial read
int ret = 0;
if (beforeIcy > 0) {
ret = stream->read(reinterpret_cast<uint8_t*>(data), beforeIcy);
if (ret < 0) ret = 0;
read += ret;
pos += ret;
len -= ret;
data = (void *)(reinterpret_cast<char*>(data) + ret);
icyByteCount += ret;
if (ret != beforeIcy) return read; // Partial read
}
uint8_t mdSize;
int mdret = stream->read(&mdSize, 1);
@@ -225,6 +229,7 @@ retry:
}
int ret = stream->read(reinterpret_cast<uint8_t*>(data), len);
if (ret < 0) ret = 0;
read += ret;
pos += ret;
icyByteCount += ret;