summaryrefslogtreecommitdiff
path: root/src/textual.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/textual.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/textual.cc')
-rw-r--r--src/textual.cc36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/textual.cc b/src/textual.cc
index 5488c6a3..4105a42d 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -349,7 +349,8 @@ std::streamsize instance_t::read_line(char *& line)
--len;
}
- while (len > 0 && std::isspace(line[len - 1])) // strip trailing whitespace
+ // strip trailing whitespace
+ while (len > 0 && std::isspace(static_cast<unsigned char>(line[len - 1])))
line[--len] = '\0';
return len;
@@ -364,7 +365,7 @@ xact_t * instance_t::read_next_directive(bool& error_flag, xact_t * previous_xac
if (len == 0 || line == NULL)
return NULL;
- if (! std::isspace(line[0]))
+ if (! std::isspace(static_cast<unsigned char>(line[0])))
error_flag = false;
switch (line[0]) {
@@ -625,12 +626,16 @@ void instance_t::automated_xact_directive(char * line)
item->pos->end_line++;
}
else if ((remlen > 7 && *p == 'a' &&
- std::strncmp(p, "assert", 6) == 0 && std::isspace(p[6])) ||
+ std::strncmp(p, "assert", 6) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[6]))) ||
(remlen > 6 && *p == 'c' &&
- std::strncmp(p, "check", 5) == 0 && std::isspace(p[5])) ||
+ std::strncmp(p, "check", 5) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[5]))) ||
(remlen > 5 && *p == 'e' &&
- ((std::strncmp(p, "expr", 4) == 0 && std::isspace(p[4])) ||
- (std::strncmp(p, "eval", 4) == 0 && std::isspace(p[4]))))) {
+ ((std::strncmp(p, "expr", 4) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[4]))) ||
+ (std::strncmp(p, "eval", 4) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[4])))))) {
const char c = *p;
p = skip_ws(&p[*p == 'a' ? 6 : (*p == 'c' ? 5 : 4)]);
if (! ae->check_exprs)
@@ -1028,7 +1033,7 @@ void instance_t::alias_directive(char * line)
{
if (char * e = std::strchr(line, '=')) {
char * z = e - 1;
- while (std::isspace(*z))
+ while (std::isspace(static_cast<unsigned char>(*z)))
*z-- = '\0';
*e++ = '\0';
e = skip_ws(e);
@@ -1247,7 +1252,7 @@ void instance_t::python_directive(char * line)
if (read_line(line) > 0) {
if (! indent) {
const char * p = line;
- while (*p && std::isspace(*p)) {
+ while (*p && std::isspace(static_cast<unsigned char>(*p))) {
++indent;
++p;
}
@@ -1255,7 +1260,7 @@ void instance_t::python_directive(char * line)
const char * p = line;
for (std::size_t i = 0; i < indent; i++) {
- if (std::isspace(*p))
+ if (std::isspace(static_cast<unsigned char>(*p)))
++p;
else
break;
@@ -1486,7 +1491,7 @@ post_t * instance_t::parse_post(char * line,
char * next = next_element(p, true);
char * e = p + std::strlen(p);
- while (e > p && std::isspace(*(e - 1)))
+ while (e > p && std::isspace(static_cast<unsigned char>(*(e - 1))))
e--;
if ((*p == '[' && *(e - 1) == ']') || (*p == '(' && *(e - 1) == ')')) {
@@ -1898,7 +1903,7 @@ xact_t * instance_t::parse_xact(char * line,
}
else if (*p == ';' && (tabs > 0 || spaces > 1)) {
char *q = p - 1;
- while (q > next && std::isspace(*q))
+ while (q > next && std::isspace(static_cast<unsigned char>(*q)))
--q;
if (q >= next)
*(q + 1) = '\0';
@@ -1951,11 +1956,14 @@ xact_t * instance_t::parse_xact(char * line,
item->pos->end_line++;
}
else if ((remlen > 7 && *p == 'a' &&
- std::strncmp(p, "assert", 6) == 0 && std::isspace(p[6])) ||
+ std::strncmp(p, "assert", 6) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[6]))) ||
(remlen > 6 && *p == 'c' &&
- std::strncmp(p, "check", 5) == 0 && std::isspace(p[5])) ||
+ std::strncmp(p, "check", 5) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[5]))) ||
(remlen > 5 && *p == 'e' &&
- std::strncmp(p, "expr", 4) == 0 && std::isspace(p[4]))) {
+ std::strncmp(p, "expr", 4) == 0 &&
+ std::isspace(static_cast<unsigned char>(p[4])))) {
const char c = *p;
p = skip_ws(&p[*p == 'a' ? 6 : (*p == 'c' ? 5 : 4)]);
expr_t expr(p);