summaryrefslogtreecommitdiff
path: root/src/format.cc
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell+ledger@mumble.net>2024-04-27 19:54:23 +0000
committerJohn Wiegley <johnw@newartisans.com>2024-08-06 14:51:38 -1000
commitd9967c2638052730c6eeb1624586d633d6482003 (patch)
treef6dd9d0a94cc633f4e1a4f0588c2cb613e0100e2 /src/format.cc
parent762353945a744ae4b89970b9e08c2c22a52ddbff (diff)
downloadfork-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/format.cc')
-rw-r--r--src/format.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/format.cc b/src/format.cc
index 708b9edd..a3596b26 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -109,7 +109,7 @@ namespace {
// Don't gobble up any whitespace
const char * base = p;
- while (p >= base && std::isspace(*p))
+ while (p >= base && std::isspace(static_cast<unsigned char>(*p)))
p--;
}
return expr;
@@ -183,7 +183,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
}
std::size_t num = 0;
- while (*p && std::isdigit(*p)) {
+ while (*p && std::isdigit(static_cast<unsigned char>(*p))) {
num *= 10;
num += static_cast<std::size_t>(*p++ - '0');
}
@@ -192,7 +192,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
if (*p == '.') {
++p;
num = 0;
- while (*p && std::isdigit(*p)) {
+ while (*p && std::isdigit(static_cast<unsigned char>(*p))) {
num *= 10;
num += static_cast<std::size_t>(*p++ - '0');
}
@@ -201,7 +201,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
current->min_width = current->max_width;
}
- if (std::isalpha(*p)) {
+ if (std::isalpha(static_cast<unsigned char>(*p))) {
bool found = false;
for (std::size_t i = 0; i < (sizeof(single_letter_mappings) /
sizeof(format_mapping_t)); i++) {
@@ -210,7 +210,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
for (const char * ptr = single_letter_mappings[i].expr; *ptr;) {
if (*ptr == '$') {
const char * beg = ++ptr;
- while (*ptr && std::isalpha(*ptr))
+ while (*ptr && std::isalpha(static_cast<unsigned char>(*ptr)))
++ptr;
string::size_type klen = static_cast<string::size_type>(ptr - beg);
string keyword(beg, 0, klen);
@@ -250,12 +250,13 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
throw_(format_error, _("Prior field reference, but no template"));
p++;
- if (*p == '0' || (! std::isdigit(*p) &&
+ if (*p == '0' || (! std::isdigit(static_cast<unsigned char>(*p)) &&
*p != 'A' && *p != 'B' && *p != 'C' &&
*p != 'D' && *p != 'E' && *p != 'F'))
throw_(format_error, _("%$ field reference must be a digit from 1-9"));
- int index = std::isdigit(*p) ? *p - '0' : (*p - 'A' + 10);
+ int index = std::isdigit(static_cast<unsigned char>(*p))
+ ? *p - '0' : (*p - 'A' + 10);
element_t * tmpl_elem = tmpl->elements.get();
for (int i = 1; i < index && tmpl_elem; i++) {
@@ -630,7 +631,8 @@ string format_t::truncate(const unistring& ustr,
if (adjust > 0) {
DEBUG("format.abbrev",
"Reducing segment " << ++index << " by " << adjust << " chars");
- while (std::isspace((*x)[*i - adjust - 1]) && adjust < *i) {
+ while (std::isspace(static_cast<unsigned char>(
+ (*x)[*i - adjust - 1])) && adjust < *i) {
DEBUG("format.abbrev",
"Segment ends in whitespace, adjusting down");
++adjust;