[vlc-commits] mkv: replaced magic `10` by real constant + fixed initialization
Filip Roséen
git at videolan.org
Sat Mar 5 22:14:45 CET 2016
vlc | branch: master | Filip Roséen <filip at atch.se> | Fri Mar 4 17:04:01 2016 +0100| [c2e0de71800fcace44f2fd05d74c5d8b799456c7] | committer: Jean-Baptiste Kempf
mkv: replaced magic `10` by real constant + fixed initialization
Since `EbmlParser::m_el` has a fixed size we should take advantage of
this and actually pass `sizeof(m_el)` directly to `memset`; especially
since the old code only initializes the first 6 pointers when the array
can potentially store 10 elements.
The magic constant 10 has been replaced by `EbmlParser::M_EL_MAXSIZE` to
make the code easier to read, and safer to use.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c2e0de71800fcace44f2fd05d74c5d8b799456c7
---
modules/demux/mkv/Ebml_parser.cpp | 6 +++---
modules/demux/mkv/Ebml_parser.hpp | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/modules/demux/mkv/Ebml_parser.cpp b/modules/demux/mkv/Ebml_parser.cpp
index 5a5f18b..2168158 100644
--- a/modules/demux/mkv/Ebml_parser.cpp
+++ b/modules/demux/mkv/Ebml_parser.cpp
@@ -40,7 +40,7 @@ EbmlParser::EbmlParser( EbmlStream *es, EbmlElement *el_start, demux_t *p_demux,
mb_dummy( b_with_dummy )
{
mi_remain_size[0] = el_start->GetSize();
- memset( m_el, 0, 6 * sizeof( *m_el ) );
+ memset( m_el, 0, sizeof( *m_el ) * M_EL_MAXSIZE);
m_el[0] = el_start;
}
@@ -253,7 +253,7 @@ EbmlElement *EbmlParser::Get( int n_call )
b_bad_position = true;
}
- if( n_call < 10 && !b_bad_position && m_el[mi_level]->IsFiniteSize() &&
+ if( n_call < M_EL_MAXSIZE && !b_bad_position && m_el[mi_level]->IsFiniteSize() &&
( !m_el[mi_level-1]->IsFiniteSize() ||
m_el[mi_level]->GetEndPosition() <= m_el[mi_level-1]->GetEndPosition() ) )
{
@@ -264,7 +264,7 @@ EbmlElement *EbmlParser::Get( int n_call )
}
else
{
- /* Too large, misplaced or 10 successive dummy elements */
+ /* Too large, misplaced or M_EL_MAXSIZE successive dummy elements */
msg_Err( p_demux,
"Dummy element too large or misplaced at %" PRIu64 "... skipping to next upper element",
m_el[mi_level]->GetElementPosition() );
diff --git a/modules/demux/mkv/Ebml_parser.hpp b/modules/demux/mkv/Ebml_parser.hpp
index 419f55f..109c572 100644
--- a/modules/demux/mkv/Ebml_parser.hpp
+++ b/modules/demux/mkv/Ebml_parser.hpp
@@ -51,10 +51,12 @@ class EbmlParser
bool IsTopPresent( EbmlElement * ) const;
private:
+ static const int M_EL_MAXSIZE = 10;
+
demux_t *p_demux;
EbmlStream *m_es;
int mi_level;
- EbmlElement *m_el[10];
+ EbmlElement *m_el[M_EL_MAXSIZE];
int64_t mi_remain_size[10];
EbmlElement *m_got;
More information about the vlc-commits
mailing list