]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pnm_parser.c
avcodec: Constify all the AVCodecParsers
[ffmpeg] / libavcodec / pnm_parser.c
index 94777d2ccaf914a39577a3b913e0c9eefd397d8c..f8eb2e7edab2dc4146c2a2be04b36ff7d79aac9b 100644 (file)
@@ -95,8 +95,11 @@ retry:
             sync = bs;
             c = *bs++;
             if (c == '#')  {
-                while (c != '\n' && bs < end)
-                    c = *bs++;
+                uint8_t *match = memchr(bs, '\n', end-bs);
+                if (match)
+                    bs = match + 1;
+                else
+                    break;
             } else if (c == 'P') {
                 next = bs - pnmctx.bytestream_start + skip - 1;
                 pnmpc->ascii_scan = 0;
@@ -106,8 +109,10 @@ retry:
         if (next == END_NOT_FOUND)
             pnmpc->ascii_scan = sync - pnmctx.bytestream + skip;
     } else {
-        next = pnmctx.bytestream - pnmctx.bytestream_start + skip
-               + av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
+        int ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1);
+        next = pnmctx.bytestream - pnmctx.bytestream_start + skip;
+        if (ret >= 0 && next + (uint64_t)ret <= INT_MAX)
+            next += ret;
     }
     if (next != END_NOT_FOUND && pnmctx.bytestream_start != buf + skip)
         next -= pc->index;
@@ -126,7 +131,7 @@ end:
     return next;
 }
 
-AVCodecParser ff_pnm_parser = {
+const AVCodecParser ff_pnm_parser = {
     .codec_ids      = { AV_CODEC_ID_PGM, AV_CODEC_ID_PGMYUV, AV_CODEC_ID_PPM,
                         AV_CODEC_ID_PBM, AV_CODEC_ID_PAM },
     .priv_data_size = sizeof(PNMParseContext),