[vlc-devel] [PATCH 03/20] mkv: replaced magic `10` by real constant + fixed initialization

Filip Roséen filip at videolabs.io
Fri Mar 4 17:04:01 CET 2016


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.
---
 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..027737b 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;
-- 
2.7.2



More information about the vlc-devel mailing list