@@ -144,12 +144,12 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
int header)
{
- const uint8_t *start;
+ const uint8_t *start = frag->data;
+ const uint8_t * const buf_end = frag->data + frag->data_size;
uint32_t start_code = -1;
int err;
- start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
- &start_code);
+ start = avpriv_find_start_code(start, buf_end, &start_code);
if (start_code >> 8 != 0x000001) {
// No start code found.
return AVERROR_INVALIDDATA;
@@ -165,10 +165,9 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
// start code in any way (as e.g. happens when there is a
// Sequence End unit at the very end of a packet).
start_code = UINT32_MAX;
- end = avpriv_find_start_code(start--, frag->data + frag->data_size,
- &start_code);
-
- // start points to the byte containing the start_code_identifier
+ end = avpriv_find_start_code(start, buf_end, &start_code);
+ start--;
+ // decrement so start points to the byte containing the start_code_identifier
// (may be the last byte of fragment->data); end points to the byte
// following the byte containing the start code identifier (or to
// the end of fragment->data).
@@ -178,6 +177,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
unit_size = (end - 4) - start;
} else {
// We didn't find a start code, so this is the final unit.
+ // There is no start code to remove from end, hence not (end - 4).
unit_size = end - start;
}