From 9a210ca2d50e02bf045866bbb2f44a33a3c48cd9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 Jul 2014 23:10:38 +0200 Subject: 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 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.) --- stream/tv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'stream/tv.c') diff --git a/stream/tv.c b/stream/tv.c index 17b1f9ecb9..726b7d0880 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include "common/msg.h" +#include "misc/ctype.h" #include "options/m_option.h" #include "options/m_config.h" @@ -628,7 +628,7 @@ static int open_tv(tvi_handle_t *tvh) int channel = 0; if (tvh->tv_param->channel) { - if (isdigit(*tvh->tv_param->channel)) + if (mp_isdigit(*tvh->tv_param->channel)) /* if tvh->tv_param->channel begins with a digit interpret it as a number */ channel = atoi(tvh->tv_param->channel); else -- cgit v1.2.3