From 97ec4869cb2edac9c1f1e74f13147575fa4df957 Mon Sep 17 00:00:00 2001 From: hyc Date: Wed, 26 May 2010 15:16:25 +0000 Subject: [PATCH] Read buffer fixes: We overallocated the buf by 4 bytes, but the result may not have needed the extra space. Also, don't return without reading at least one packet. (Alternative: return early, but set EAGAIN...) git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@485 400ebc74-4327-4243-bc38-086b20814532 --- librtmp/rtmp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c index c3a9fbb..1c9f52d 100644 --- a/librtmp/rtmp.c +++ b/librtmp/rtmp.c @@ -4052,9 +4052,10 @@ Read_1_Packet(RTMP *r, char *buf, unsigned int buflen) if (recopy) { - memcpy(buf, r->m_read.buf, buflen); - r->m_read.bufpos = r->m_read.buf + buflen; - r->m_read.buflen = ret - buflen; + len = ret > buflen ? buflen : ret; + memcpy(buf, r->m_read.buf, len); + r->m_read.bufpos = r->m_read.buf + len; + r->m_read.buflen = ret - len; } return ret; } @@ -4162,11 +4163,13 @@ fail: size -= nRead; } - if (size > 0 && (nRead = Read_1_Packet(r, buf, size)) >= 0) + while (size > 0 && (nRead = Read_1_Packet(r, buf, size)) >= 0) { + if (!nRead) continue; buf += nRead; total += nRead; size -= nRead; + break; } if (nRead < 0) r->m_read.status = nRead; -- 2.40.0