mkvparser: Segment::AppendCluster asserts to error checks.

Change-Id: Id6bb378b22a7c6397e3d950c2fdd84396279e881
This commit is contained in:
Tom Finegan 2015-08-31 11:06:58 -07:00
parent 4630f80f79
commit b108695b9b

View File

@ -1277,16 +1277,16 @@ long Segment::DoLoadClusterUnknownSize(long long& pos, long& len) {
}
bool Segment::AppendCluster(Cluster* pCluster) {
assert(pCluster);
assert(pCluster->m_index >= 0);
if (pCluster == NULL || pCluster->m_index < 0)
return false;
const long count = m_clusterCount + m_clusterPreloadCount;
long& size = m_clusterSize;
assert(size >= count);
const long idx = pCluster->m_index;
assert(idx == m_clusterCount);
if (size < count || idx != m_clusterCount)
return false;
if (count >= size) {
const long n = (size <= 0) ? 2048 : 2 * size;
@ -1294,8 +1294,8 @@ bool Segment::AppendCluster(Cluster* pCluster) {
Cluster** const qq = new (std::nothrow) Cluster*[n];
if (qq == NULL)
return false;
Cluster** q = qq;
Cluster** q = qq;
Cluster** p = m_clusters;
Cluster** const pp = p + count;
@ -1309,18 +1309,18 @@ bool Segment::AppendCluster(Cluster* pCluster) {
}
if (m_clusterPreloadCount > 0) {
assert(m_clusters);
Cluster** const p = m_clusters + m_clusterCount;
assert(*p);
assert((*p)->m_index < 0);
if (*p == NULL || (*p)->m_index >= 0)
return false;
Cluster** q = p + m_clusterPreloadCount;
assert(q < (m_clusters + size));
if (q >= (m_clusters + size))
return false;
for (;;) {
Cluster** const qq = q - 1;
assert((*qq)->m_index < 0);
if ((*qq)->m_index >= 0)
return false;
*q = *qq;
q = qq;