diff mbox series

[FFmpeg-devel,5/8] avpriv_find_start_code(): replace unnecessary for loop

Message ID 20220201212056.29712-6-scott.the.elm@gmail.com
State New
Headers show
Series rewrite avpriv_find_start_code() for clarity | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Scott Theisen Feb. 1, 2022, 9:20 p.m. UTC
start_code will still be invalid, i.e. all ones, but will no longer have
up to the first three bytes in p shifted in.
---
 libavcodec/utils.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 54c9dd056d..b4c5fa5009 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -944,19 +944,14 @@  const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
                                       const uint8_t *end,
                                       uint32_t *av_restrict start_code)
 {
-    int i;
+    *start_code = ~0;
 
     av_assert0(p <= end);
-    if (p >= end)
+    // minimum length for a start code
+    if (p + 4 > end)
         return end;
 
-    *start_code = ~0;
-    for (i = 0; i < 3; i++) {
-        uint32_t tmp = *start_code << 8;
-        *start_code = tmp + *(p++);
-        if (tmp == 0x100 || p == end)
-            return p;
-    }
+    p += 3; // offset for negative indices in while loop
 
     /* with memory address increasing left to right, we are looking for (in hexadecimal):
      * 00 00 01 XX