Commit 03beac5b authored by Paul B Mahol's avatar Paul B Mahol

avcodec/xpmdec: define constants

parent 00502370
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#define MIN_ELEMENT ' '
#define MAX_ELEMENT 0xfe
#define NB_ELEMENTS (MAX_ELEMENT - MIN_ELEMENT + 1)
typedef struct XPMContext { typedef struct XPMContext {
uint32_t *pixels; uint32_t *pixels;
int pixels_size; int pixels_size;
...@@ -290,10 +294,10 @@ static int ascii2index(const uint8_t *cpixel, int cpp) ...@@ -290,10 +294,10 @@ static int ascii2index(const uint8_t *cpixel, int cpp)
int n = 0, m = 1, i; int n = 0, m = 1, i;
for (i = 0; i < cpp; i++) { for (i = 0; i < cpp; i++) {
if (*p < ' ' || *p > 0xfe) if (*p < MIN_ELEMENT || *p > MAX_ELEMENT)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
n += (*p++ - ' ') * m; n += (*p++ - MIN_ELEMENT) * m;
m *= 223; m *= NB_ELEMENTS;
} }
return n; return n;
} }
...@@ -346,7 +350,7 @@ static int xpm_decode_frame(AVCodecContext *avctx, void *data, ...@@ -346,7 +350,7 @@ static int xpm_decode_frame(AVCodecContext *avctx, void *data,
size = 1; size = 1;
for (i = 0; i < cpp; i++) for (i = 0; i < cpp; i++)
size *= 223; size *= NB_ELEMENTS;
if (ncolors <= 0 || ncolors > size) { if (ncolors <= 0 || ncolors > size) {
av_log(avctx, AV_LOG_ERROR, "invalid number of colors: %d\n", ncolors); av_log(avctx, AV_LOG_ERROR, "invalid number of colors: %d\n", ncolors);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment