X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fpnm.c;h=a9771710c2a68003bfd565383b34e192dcb7d05c;hb=e2f766e13f0350017a0c3c7111b54cda7317e500;hp=b06a6e81b5190c987e02fd04c0f0e21208707cb5;hpb=b4ca32414ea28ad29b4bd387c298f5a676dace2a;p=ffmpeg diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index b06a6e81b51..a9771710c2a 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -36,13 +36,15 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size) { char *s; int c; + uint8_t *bs = sc->bytestream; + const uint8_t *end = sc->bytestream_end; /* skip spaces and comments */ - while (sc->bytestream < sc->bytestream_end) { - c = *sc->bytestream++; + while (bs < end) { + c = *bs++; if (c == '#') { - while (c != '\n' && sc->bytestream < sc->bytestream_end) { - c = *sc->bytestream++; + while (c != '\n' && bs < end) { + c = *bs++; } } else if (!pnm_space(c)) { break; @@ -50,12 +52,14 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size) } s = str; - while (sc->bytestream < sc->bytestream_end && !pnm_space(c)) { - if ((s - str) < buf_size - 1) - *s++ = c; - c = *sc->bytestream++; + while (bs < end && !pnm_space(c) && (s - str) < buf_size - 1) { + *s++ = c; + c = *bs++; } *s = '\0'; + while (bs < end && !pnm_space(c)) + c = *bs++; + sc->bytestream = bs; } int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)