summaryrefslogtreecommitdiffstats
path: root/sub/find_subfiles.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-01 23:10:38 +0200
committerwm4 <wm4@nowhere>2014-07-01 23:11:08 +0200
commit9a210ca2d50e02bf045866bbb2f44a33a3c48cd9 (patch)
tree9f685c66c9d3b2e968416c7f60d30ea56ab1f9bb /sub/find_subfiles.c
parent0208ad4f3b4d2331b8242bb6fb12a9a4475ccae6 (diff)
downloadmpv-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 'sub/find_subfiles.c')
-rw-r--r--sub/find_subfiles.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c
index 9313bf379d..ade267cfa6 100644
--- a/sub/find_subfiles.c
+++ b/sub/find_subfiles.c
@@ -1,16 +1,16 @@
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
-#include <ctype.h>
#include <assert.h>
#include "osdep/io.h"
+#include "common/common.h"
#include "common/global.h"
#include "common/msg.h"
+#include "misc/ctype.h"
#include "options/options.h"
#include "options/path.h"
-#include "common/common.h"
#include "sub/find_subfiles.h"
static const char *const sub_exts[] = {"utf", "utf8", "utf-8", "idx", "sub", "srt",
@@ -75,7 +75,7 @@ static struct bstr guess_lang_from_filename(struct bstr name)
if (name.start[i] == ')' || name.start[i] == ']')
i--;
- while (i >= 0 && isalpha(name.start[i])) {
+ while (i >= 0 && mp_isalpha(name.start[i])) {
n++;
if (n > 3)
return (struct bstr){NULL, 0};