mkvparser: Cluster::Load clean up.

- Remove "// weird"'s.
- Remove needless extra scoping.
- Asserts to error checks.

Change-Id: I5c4d1bbc59d9debe95e1e35e63ff0679335048ff
This commit is contained in:
Tom Finegan 2015-08-31 13:59:35 -07:00
parent 27a07c1fd1
commit 19f5694277

View File

@ -5650,32 +5650,29 @@ const Track* Tracks::GetTrackByIndex(unsigned long idx) const {
} }
long Cluster::Load(long long& pos, long& len) const { long Cluster::Load(long long& pos, long& len) const {
assert(m_pSegment); if (m_pSegment == NULL)
assert(m_pos >= m_element_start); return E_PARSE_FAILED;
if (m_timecode >= 0) // at least partially loaded if (m_timecode >= 0) // at least partially loaded
return 0; return 0;
assert(m_pos == m_element_start); if (m_pos != m_element_start || m_element_size >= 0)
assert(m_element_size < 0); return E_PARSE_FAILED;
IMkvReader* const pReader = m_pSegment->m_pReader; IMkvReader* const pReader = m_pSegment->m_pReader;
long long total, avail; long long total, avail;
const int status = pReader->Length(&total, &avail); const int status = pReader->Length(&total, &avail);
if (status < 0) // error if (status < 0) // error
return status; return status;
assert((total < 0) || (avail <= total)); if (total >= 0 && (avail > total || m_pos > total))
assert((total < 0) || (m_pos <= total)); // TODO: verify this return E_FILE_FORMAT_INVALID;
pos = m_pos; pos = m_pos;
long long cluster_size = -1; long long cluster_size = -1;
{
if ((pos + 1) > avail) { if ((pos + 1) > avail) {
len = 1; len = 1;
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
@ -5686,12 +5683,9 @@ long Cluster::Load(long long& pos, long& len) const {
if (result < 0) // error or underflow if (result < 0) // error or underflow
return static_cast<long>(result); return static_cast<long>(result);
if (result > 0) // underflow (weird) if (result > 0)
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
// if ((pos + len) > segment_stop)
// return E_FILE_FORMAT_INVALID;
if ((pos + len) > avail) if ((pos + len) > avail)
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
@ -5717,12 +5711,9 @@ long Cluster::Load(long long& pos, long& len) const {
if (result < 0) // error if (result < 0) // error
return static_cast<long>(result); return static_cast<long>(result);
if (result > 0) // weird if (result > 0)
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
// if ((pos + len) > segment_stop)
// return E_FILE_FORMAT_INVALID;
if ((pos + len) > avail) if ((pos + len) > avail)
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
@ -5732,7 +5723,7 @@ long Cluster::Load(long long& pos, long& len) const {
return static_cast<long>(cluster_size); return static_cast<long>(cluster_size);
if (size == 0) if (size == 0)
return E_FILE_FORMAT_INVALID; // TODO: verify this return E_FILE_FORMAT_INVALID;
pos += len; // consume length of size of element pos += len; // consume length of size of element
@ -5740,7 +5731,6 @@ long Cluster::Load(long long& pos, long& len) const {
if (size != unknown_size) if (size != unknown_size)
cluster_size = size; cluster_size = size;
}
// pos points to start of payload // pos points to start of payload
long long timecode = -1; long long timecode = -1;
@ -5765,7 +5755,7 @@ long Cluster::Load(long long& pos, long& len) const {
if (result < 0) // error if (result < 0) // error
return static_cast<long>(result); return static_cast<long>(result);
if (result > 0) // weird if (result > 0)
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
if ((cluster_stop >= 0) && ((pos + len) > cluster_stop)) if ((cluster_stop >= 0) && ((pos + len) > cluster_stop))
@ -5806,7 +5796,7 @@ long Cluster::Load(long long& pos, long& len) const {
if (result < 0) // error if (result < 0) // error
return static_cast<long>(result); return static_cast<long>(result);
if (result > 0) // weird if (result > 0)
return E_BUFFER_NOT_FULL; return E_BUFFER_NOT_FULL;
if ((cluster_stop >= 0) && ((pos + len) > cluster_stop)) if ((cluster_stop >= 0) && ((pos + len) > cluster_stop))
@ -5832,7 +5822,7 @@ long Cluster::Load(long long& pos, long& len) const {
// pos now points to start of payload // pos now points to start of payload
if (size == 0) // weird if (size == 0)
continue; continue;
if ((cluster_stop >= 0) && ((pos + size) > cluster_stop)) if ((cluster_stop >= 0) && ((pos + size) > cluster_stop))