mkvparser: Segment assert clean up.

- Remove asserts from ~Segment, CreateInstance, and DoLoadCluster.
- Adds new return constant (E_PARSE_FAILED == -1); most places in
  mkvparser that return -1 are the result of an internal inconsistency
  and/or misusing the API. In those cases E_FILE_FORMAT_INVALID is not
  appropriate as a return value because it's misleading to libwebm users.

Change-Id: I0d46e831b3475d69432b8745066de3329419fa11
This commit is contained in:
Tom Finegan
2015-08-28 14:53:47 -07:00
parent 0735bb5bdc
commit 841a9b5fd9
2 changed files with 18 additions and 14 deletions

View File

@@ -632,8 +632,6 @@ Segment::~Segment() {
while (i != j) { while (i != j) {
Cluster* const p = *i++; Cluster* const p = *i++;
assert(p);
delete p; delete p;
} }
@@ -649,8 +647,8 @@ Segment::~Segment() {
long long Segment::CreateInstance(IMkvReader* pReader, long long pos, long long Segment::CreateInstance(IMkvReader* pReader, long long pos,
Segment*& pSegment) { Segment*& pSegment) {
assert(pReader); if (pReader == NULL || pos < 0)
assert(pos >= 0); return E_PARSE_FAILED;
pSegment = NULL; pSegment = NULL;
@@ -993,7 +991,8 @@ long Segment::DoLoadCluster(long long& pos, long& len) {
if (status < 0) // error if (status < 0) // error
return status; return status;
assert((total < 0) || (avail <= total)); if (total >= 0 && avail > total)
return E_FILE_FORMAT_INVALID;
const long long segment_stop = (m_size < 0) ? -1 : m_start + m_size; const long long segment_stop = (m_size < 0) ? -1 : m_start + m_size;
@@ -1114,7 +1113,10 @@ long Segment::DoLoadCluster(long long& pos, long& len) {
break; break;
} }
assert(cluster_off >= 0); // have cluster if (cluster_off < 0) {
// No cluster, die.
return E_FILE_FORMAT_INVALID;
}
long long pos_; long long pos_;
long len_; long len_;
@@ -1160,14 +1162,16 @@ long Segment::DoLoadCluster(long long& pos, long& len) {
const long idx = m_clusterCount; const long idx = m_clusterCount;
if (m_clusterPreloadCount > 0) { if (m_clusterPreloadCount > 0) {
assert(idx < m_clusterSize); if (idx >= m_clusterSize)
return E_FILE_FORMAT_INVALID;
Cluster* const pCluster = m_clusters[idx]; Cluster* const pCluster = m_clusters[idx];
assert(pCluster); if (pCluster == NULL || pCluster->m_index >= 0)
assert(pCluster->m_index < 0); return E_FILE_FORMAT_INVALID;
const long long off = pCluster->GetPosition(); const long long off = pCluster->GetPosition();
assert(off >= 0); if (off < 0)
return E_FILE_FORMAT_INVALID;
if (off == cluster_off) { // preloaded already if (off == cluster_off) { // preloaded already
if (status == 0) // no entries found if (status == 0) // no entries found
@@ -1224,15 +1228,14 @@ long Segment::DoLoadCluster(long long& pos, long& len) {
delete pCluster; delete pCluster;
return -1; return -1;
} }
assert(m_clusters);
assert(idx < m_clusterSize);
assert(m_clusters[idx] == pCluster);
if (cluster_size >= 0) { if (cluster_size >= 0) {
pos += cluster_size; pos += cluster_size;
m_pos = pos; m_pos = pos;
assert((segment_stop < 0) || (m_pos <= segment_stop));
if (segment_stop > 0 && m_pos > segment_stop)
return E_FILE_FORMAT_INVALID;
return 0; return 0;
} }

View File

@@ -15,6 +15,7 @@
namespace mkvparser { namespace mkvparser {
const int E_PARSE_FAILED = -1;
const int E_FILE_FORMAT_INVALID = -2; const int E_FILE_FORMAT_INVALID = -2;
const int E_BUFFER_NOT_FULL = -3; const int E_BUFFER_NOT_FULL = -3;