]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
parser h264: fix h264_nal_deescape regression
authorJaroslav Kysela <perex@perex.cz>
Thu, 24 Sep 2015 21:41:04 +0000 (23:41 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 24 Sep 2015 22:03:59 +0000 (00:03 +0200)
src/parsers/parser_h264.c

index bbad3d86d1b2f147784adc8b979645a5030f06b2..94bc1b3ac5f1dc2aaba8c4145362e257b376c613 100644 (file)
 void *
 h264_nal_deescape(bitstream_t *bs, const uint8_t *data, int size)
 {
-  int_fast32_t i = 0;
   uint_fast8_t c;
   uint8_t *d;
+  const uint8_t *end, *end2;
 
   bs->rdata = d = malloc(size);
   bs->offset = 0;
 
+  end2 = data + size;
+
   if (size > 2) {
 
-  /* Escape 0x000003 into 0x0000 */
+    /* Escape 0x000003 into 0x0000 */
 
-    for( ; i < size - 2; i++) {
+    end = end2 - 2;
+    while (data < end) {
       c = *data++;
-      if (c || data[1] || data[2] != 3) {
+      if (c || *data || *(data + 1) != 3) {
         *d++ = c;
-        continue;
+      } else {
+        *d++ = 0;
+        *d++ = 0;
+        data += 2;
       }
-      *d++ = 0;
-      *d++ = 0;
-      i+= 2;
     }
 
   }
 
-  for (; i < size; i++)
+  while (data < end2)
     *d++ = *data++;
 
   bs->len = (d - bs->rdata) * 8;
-  return d;
+  return (void *)bs->rdata;
 }