diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c index 5339bebde9..58c3cd2431 100644 --- a/libavcodec/pnm_parser.c +++ b/libavcodec/pnm_parser.c @@ -92,8 +92,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;