[MPlayer-cvslog] r38394 - trunk/libmpdemux/mpeg_hdr.c

reimar subversion at mplayerhq.hu
Sat Aug 27 11:40:45 EEST 2022


Author: reimar
Date: Sat Aug 27 11:40:45 2022
New Revision: 38394

Log:
mpeg_hdr.c: Improve read_golomb code.

Limit how much it reads at most and simplify shift.

Modified:
   trunk/libmpdemux/mpeg_hdr.c

Modified: trunk/libmpdemux/mpeg_hdr.c
==============================================================================
--- trunk/libmpdemux/mpeg_hdr.c	Sat Aug 27 11:37:31 2022	(r38393)
+++ trunk/libmpdemux/mpeg_hdr.c	Sat Aug 27 11:40:45 2022	(r38394)
@@ -286,7 +286,9 @@ static unsigned int read_golomb(unsigned
 {
   unsigned int x, v = 0, v2 = 0, m, len = 0, n = *init;
 
-  while(getbits(buffer, n++, 1) == 0)
+  // TODO: check exact length limit.
+  // Remaining code breaks values > 31 anyway though
+  while(getbits(buffer, n++, 1) == 0 && len < 31)
     len++;
 
   x = len + n;
@@ -299,9 +301,7 @@ static unsigned int read_golomb(unsigned
       v <<= 8;
   }
 
-  v2 = 1;
-  for(n = 0; n < len; n++)
-    v2 <<= 1;
+  v2 = 1u << len;
   v2 = (v2 - 1) + v;
 
   //fprintf(stderr, "READ_GOLOMB(%u), V=2^%u + %u-1 = %u\n", *init, len, v, v2);


More information about the MPlayer-cvslog mailing list