[FFmpeg-devel,v3] avcodec/h2645_parse: refine the code for better readiablity

Submitted by lance.lmwang@gmail.com on Sept. 14, 2019, 3:01 a.m.

Details

Message ID 20190914030155.19292-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Sept. 14, 2019, 3:01 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/h2645_parse.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index ef6a6b4..8b9595a 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -453,23 +453,22 @@  int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
             }
         }
 
-        if (pkt->nals_allocated < pkt->nb_nals + 1) {
-            int new_size = pkt->nals_allocated + 1;
-            void *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*pkt->nals));
+        if (pkt->nb_nals >= pkt->nals_allocated) {
+            void *tmp = av_realloc_array(pkt->nals, pkt->nals_allocated + 1, sizeof(*pkt->nals));
 
             if (!tmp)
                 return AVERROR(ENOMEM);
 
             pkt->nals = tmp;
-            memset(pkt->nals + pkt->nals_allocated, 0, sizeof(*pkt->nals));
+            nal = &pkt->nals[pkt->nals_allocated];
 
-            nal = &pkt->nals[pkt->nb_nals];
+            memset(nal, 0, sizeof(*pkt->nals));
             nal->skipped_bytes_pos_size = 1024; // initial buffer size
             nal->skipped_bytes_pos = av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos));
             if (!nal->skipped_bytes_pos)
                 return AVERROR(ENOMEM);
 
-            pkt->nals_allocated = new_size;
+            pkt->nals_allocated++;
         }
         nal = &pkt->nals[pkt->nb_nals];