[vlc-commits] demux: ps: use switch and fix oob

Francois Cartegnie git at videolan.org
Tue Mar 7 18:10:53 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Mar  7 18:07:17 2017 +0100| [b6707b47d2ed4df3b053336add7da8e377958345] | committer: Francois Cartegnie

demux: ps: use switch and fix oob

no joycons here

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b6707b47d2ed4df3b053336add7da8e377958345
---

 modules/demux/mpeg/ps.h | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/modules/demux/mpeg/ps.h b/modules/demux/mpeg/ps.h
index e9c3788..5eb94e3 100644
--- a/modules/demux/mpeg/ps.h
+++ b/modules/demux/mpeg/ps.h
@@ -342,28 +342,29 @@ static inline int ps_pkt_id( block_t *p_pkt )
 static inline int ps_pkt_size( const uint8_t *p, int i_peek )
 {
     if( unlikely(i_peek < 4) )
-    {
         return -1;
-    }
-    else if( p[3] == PS_STREAM_ID_END_STREAM )
-    {
-        return 4;
-    }
-    else if( p[3] == PS_STREAM_ID_PACK_HEADER )
-    {
-        if( i_peek >= 14 && (p[4] >> 6) == 0x01 )
-        {
-            return 14 + (p[13]&0x07);
-        }
-        else if( i_peek >= 12 && (p[4] >> 4) == 0x02 )
-        {
-            return 12;
-        }
-        return -1;
-    }
-    else if( i_peek >= 6 )
+
+    switch( p[3] )
     {
-        return 6 + ((p[4]<<8) | p[5] );
+        case PS_STREAM_ID_END_STREAM:
+            return 4;
+
+        case PS_STREAM_ID_PACK_HEADER:
+            if( i_peek > 4 )
+            {
+                if( i_peek >= 14 && (p[4] >> 6) == 0x01 )
+                    return 14 + (p[13]&0x07);
+                else if( i_peek >= 12 && (p[4] >> 4) == 0x02 )
+                    return 12;
+            }
+            break;
+
+        case PS_STREAM_ID_SYSTEM_HEADER:
+        case PS_STREAM_ID_MAP:
+        case PS_STREAM_ID_DIRECTORY:
+        default:
+            if( i_peek >= 6 )
+                return 6 + ((p[4]<<8) | p[5] );
     }
     return -1;
 }



More information about the vlc-commits mailing list