diff options
author | Taylor R Campbell <campbell+ledger@mumble.net> | 2024-04-27 19:54:23 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2024-08-06 14:51:38 -1000 |
commit | d9967c2638052730c6eeb1624586d633d6482003 (patch) | |
tree | f6dd9d0a94cc633f4e1a4f0588c2cb613e0100e2 /src/times.cc | |
parent | 762353945a744ae4b89970b9e08c2c22a52ddbff (diff) | |
download | fork-ledger-d9967c2638052730c6eeb1624586d633d6482003.tar.gz fork-ledger-d9967c2638052730c6eeb1624586d633d6482003.tar.bz2 fork-ledger-d9967c2638052730c6eeb1624586d633d6482003.zip |
Avoid ctype abuse.
fix https://github.com/ledger/ledger/issues/2338
fix https://github.com/ledger/ledger/issues/2340
Diffstat (limited to 'src/times.cc')
-rw-r--r-- | src/times.cc | 22 |
1 files changed, 13 insertions, 9 deletions
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<unsigned char>(*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<unsigned char>(*begin))) { string::const_iterator i = begin; - for (i = begin; i != end && ! std::isspace(*i); i++) {} + for (i = begin; + i != end && ! std::isspace(static_cast<unsigned char>(*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<bool>(std::isalnum(*begin))) || - (! alnum && ! static_cast<bool>(std::isalnum(*begin))))); begin++) + bool alnum = std::isalnum(static_cast<unsigned char>(*begin)); + for (; (begin != end && ! std::isspace(static_cast<unsigned char>(*begin)) && + ((alnum && static_cast<bool>(std::isalnum( + static_cast<unsigned char>(*begin)))) || + (! alnum && ! static_cast<bool>(std::isalnum( + static_cast<unsigned char>(*begin)))))); begin++) term.push_back(*begin); if (! term.empty()) { - if (std::isdigit(term[0])) { + if (std::isdigit(static_cast<unsigned char>(term[0]))) { return token_t(token_t::TOK_INT, token_t::content_t(lexical_cast<unsigned short>(term))); } - else if (std::isalpha(term[0])) { + else if (std::isalpha(static_cast<unsigned char>(term[0]))) { to_lower(term); if (optional<date_time::months_of_year> month = |