fix some undefined behaviour with ctype functions - bmf - bmf (Bayesian Mail Filter) 0.9.4 fork + patches
 (HTM) git clone git://git.codemadness.org/bmf
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 20a0f52d5b478e240450fd72fa3bbd3ab5c58c48
 (DIR) parent f368a24da9457e4d269ca281bbc07f0eef08751e
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Thu, 25 Oct 2018 12:41:39 +0200
       
       fix some undefined behaviour with ctype functions
       
       Diffstat:
         M lex.c                               |      31 ++++++++++++++++---------------
       
       1 file changed, 16 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/lex.c b/lex.c
       @@ -188,19 +188,13 @@ is_whitespace(int c)
        }
        
        static inline bool_t
       -is_base64char(c)
       -{
       -        return (isalnum(c) || (c == '/' || c == '+'));
       -}
       -
       -static inline bool_t
       -is_wordmidchar(c)
       +is_wordmidchar(int c)
        {
                return (isalnum(c) || c == '$' || c == '\'' || c == '.' || c == '-');
        }
        
        static inline bool_t
       -is_wordendchar(c)
       +is_wordendchar(int c)
        {
                return (isalnum(c) || c == '$');
        }
       @@ -228,10 +222,11 @@ is_htmltag(cpchar p, uint len, uint * ptoklen)
                        return false;
                }
                /* check if is_word() will have a longer match */
       -        if (is_wordendchar(p[minlen])) {
       +        if (is_wordendchar((unsigned char)p[minlen])) {
                        return false;
                }
       -        if (is_wordmidchar(p[minlen]) && is_wordendchar(p[minlen + 1])) {
       +        if (is_wordmidchar((unsigned char)p[minlen]) &&
       +            is_wordendchar((unsigned char)p[minlen + 1])) {
                        return false;
                }
                *ptoklen = strlen(g_htmltags[hi]);
       @@ -256,11 +251,17 @@ is_htmlcomment(cpchar p, uint len, uint * ptoklen)
        }
        
        static inline bool_t
       +is_base64char(int c)
       +{
       +        return (isalnum(c) || (c == '/' || c == '+'));
       +}
       +
       +static inline bool_t
        is_base64(cpchar p, uint len, uint * ptoklen)
        {
                *ptoklen = 0;
                while (len > 0) {
       -                if (*p != '\n' && *p != '\r' && !is_base64char(*p)) {
       +                if (*p != '\n' && *p != '\r' && !is_base64char((unsigned char)*p)) {
                                return false;
                        }
                        p++;
       @@ -305,7 +306,7 @@ is_ipaddr(cpchar p, uint len, uint * ptoklen)
                noctets = 0;
                while (len > 0 && noctets < 4) {
                        ndigits = 0;
       -                while (len > 0 && isdigit(*p)) {
       +                while (len > 0 && isdigit((unsigned char)*p)) {
                                ndigits++;
                                p++;
                                len--;
       @@ -336,21 +337,21 @@ is_word(cpchar p, uint len, uint * ptoklen)
                if (len < 3) {
                        return false;
                }
       -        if (!(isalpha(*p) || *p == '$')) {
       +        if (!(isalpha((unsigned char)*p) || *p == '$')) {
                        return false;
                }
                *ptoklen = 1;
                p++;
                len--;
                while (len > 0) {
       -                if (!is_wordmidchar(*p)) {
       +                if (!is_wordmidchar((unsigned char)*p)) {
                                break;
                        }
                        (*ptoklen)++;
                        p++;
                        len--;
                }
       -        while (*ptoklen >= 3 && !is_wordendchar(*(p - 1))) {
       +        while (*ptoklen >= 3 && !is_wordendchar((unsigned char)*(p - 1))) {
                        (*ptoklen)--;
                        p--;
                        len++;