From 26bbd972dd3bdc73baa9362a2794dfc3ec3ad085 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 25 Sep 2020 17:21:33 -0400 Subject: [PATCH] Cast ctype.h inputs to unsigned char Fuckings to glibc, jesus christ that code was a nightmare Read glibc's ctype.h and then compare it to musl's src/ctype/isalpha.c --- src/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 8c5ffeb..cc104f1 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,7 @@ static struct str *parse_section(struct parser *p) { uint32_t ch; char *subsection; while ((ch = parser_getch(p)) != UTF8_INVALID) { - if (ch < 0x80 && isalnum(ch)) { + if (ch < 0x80 && isalnum((unsigned char)ch)) { int ret = str_append_ch(section, ch); assert(ret != -1); } else if (ch == ')') { @@ -112,7 +112,8 @@ static void parse_preamble(struct parser *p) { struct tm *date_tm = gmtime(&date_time); strftime(date, sizeof(date), "%F", date_tm); while ((ch = parser_getch(p)) != UTF8_INVALID) { - if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') { + if ((ch < 0x80 && isalnum((unsigned char)ch)) + || ch == '_' || ch == '-' || ch == '.') { int ret = str_append_ch(name, ch); assert(ret != -1); } else if (ch == '(') { @@ -220,7 +221,9 @@ static void parse_text(struct parser *p) { break; case '_': next = parser_getch(p); - if (!isalnum(last) || ((p->flags & FORMAT_UNDERLINE) && !isalnum(next))) { + if (!isalnum((unsigned char)last) || ( + (p->flags & FORMAT_UNDERLINE) && + !isalnum((unsigned char)next))) { parse_format(p, FORMAT_UNDERLINE); } else { utf8_fputch(p->output, ch);