From d9967c2638052730c6eeb1624586d633d6482003 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 27 Apr 2024 19:54:23 +0000 Subject: Avoid ctype abuse. fix https://github.com/ledger/ledger/issues/2338 fix https://github.com/ledger/ledger/issues/2340 --- src/times.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/times.cc') diff --git a/src/times.cc b/src/times.cc index b66a6e30..89ffd710 100644 --- a/src/times.cc +++ b/src/times.cc @@ -1477,7 +1477,7 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token() return tok; } - while (begin != end && std::isspace(*begin)) + while (begin != end && std::isspace(static_cast(*begin))) begin++; if (begin == end) @@ -1496,9 +1496,11 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token() // date using the typical date formats. This allows not only dates like // "2009/08/01", but also dates that fit the user's --input-date-format, // assuming their format fits in one argument and begins with a digit. - if (std::isdigit(*begin)) { + if (std::isdigit(static_cast(*begin))) { string::const_iterator i = begin; - for (i = begin; i != end && ! std::isspace(*i); i++) {} + for (i = begin; + i != end && ! std::isspace(static_cast(*i)); + i++) {} assert(i != begin); string possible_date(start, i); @@ -1523,18 +1525,20 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token() start = begin; string term; - bool alnum = std::isalnum(*begin); - for (; (begin != end && ! std::isspace(*begin) && - ((alnum && static_cast(std::isalnum(*begin))) || - (! alnum && ! static_cast(std::isalnum(*begin))))); begin++) + bool alnum = std::isalnum(static_cast(*begin)); + for (; (begin != end && ! std::isspace(static_cast(*begin)) && + ((alnum && static_cast(std::isalnum( + static_cast(*begin)))) || + (! alnum && ! static_cast(std::isalnum( + static_cast(*begin)))))); begin++) term.push_back(*begin); if (! term.empty()) { - if (std::isdigit(term[0])) { + if (std::isdigit(static_cast(term[0]))) { return token_t(token_t::TOK_INT, token_t::content_t(lexical_cast(term))); } - else if (std::isalpha(term[0])) { + else if (std::isalpha(static_cast(term[0]))) { to_lower(term); if (optional month = -- cgit v1.2.3