diff options
author | wm4 <wm4@nowhere> | 2014-07-01 23:10:38 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-07-01 23:11:08 +0200 |
commit | 9a210ca2d50e02bf045866bbb2f44a33a3c48cd9 (patch) | |
tree | 9f685c66c9d3b2e968416c7f60d30ea56ab1f9bb /video/out/pnm_loader.c | |
parent | 0208ad4f3b4d2331b8242bb6fb12a9a4475ccae6 (diff) | |
download | mpv-9a210ca2d50e02bf045866bbb2f44a33a3c48cd9.tar.bz2 mpv-9a210ca2d50e02bf045866bbb2f44a33a3c48cd9.tar.xz |
Audit and replace all ctype.h uses
Something like "char *s = ...; isdigit(s[0]);" triggers undefined
behavior, because char can be signed, and thus s[0] can be a negative
value. The is*() functions require unsigned char _or_ EOF. EOF is a
special value outside of unsigned char range, thus the argument to the
is*() functions can't be a char.
This undefined behavior can actually trigger crashes if the
implementation of these functions e.g. uses lookup tables, which are
then indexed with out-of-range values.
Replace all <ctype.h> uses with our own custom mp_is*() functions added
with misc/ctype.h. As a bonus, these functions are locale-independent.
(Although currently, we _require_ C locale for other reasons.)
Diffstat (limited to 'video/out/pnm_loader.c')
-rw-r--r-- | video/out/pnm_loader.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/video/out/pnm_loader.c b/video/out/pnm_loader.c index 048461e51f..70afe0fa23 100644 --- a/video/out/pnm_loader.c +++ b/video/out/pnm_loader.c @@ -33,7 +33,7 @@ #include <stdlib.h> #include <stdint.h> #include <stdio.h> -#include <ctype.h> +#include "misc/ctype.h" #include "pnm_loader.h" /** @@ -48,7 +48,7 @@ static void ppm_skip(FILE *f) { comment = 1; if (c == '\n') comment = 0; - } while (c != EOF && (isspace(c) || comment)); + } while (c != EOF && (mp_isspace(c) || comment)); if (c != EOF) ungetc(c, f); } @@ -77,7 +77,7 @@ uint8_t *read_pnm(FILE *f, int *width, int *height, if (fscanf(f, "%u", &m) != 1) return NULL; val = fgetc(f); - if (!isspace(val)) + if (!mp_isspace(val)) return NULL; if (w > MAXDIM || h > MAXDIM) return NULL; |