summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorkanreki <32443233+kanreki@users.noreply.github.com>2021-09-14 12:15:53 -0700
committerJohn Wiegley <johnw@newartisans.com>2021-12-08 16:17:17 -0800
commit586abd208221761a6c93bc4568513e9cd4dc287d (patch)
treed3d6c8da7e4584665bb705c25a91c5c66083de65 /src/commodity.cc
parented5886921bcce0d1a261a37aa83bf135259b7d21 (diff)
downloadfork-ledger-586abd208221761a6c93bc4568513e9cd4dc287d.tar.gz
fork-ledger-586abd208221761a6c93bc4568513e9cd4dc287d.tar.bz2
fork-ledger-586abd208221761a6c93bc4568513e9cd4dc287d.zip
Use correct int return type for stream input operations
This makes it safe to compare results to -1 to indicate EOF, regardless of whether char is considered signed or unsigned; and so eliminates compiler warnings on platforms such as ARM. Fixes bug #2058.
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index ebe388c8..29c04e59 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -297,12 +297,12 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
std::istream::pos_type pos = in.tellg();
char buf[256];
- char c = peek_next_nonws(in);
+ int c = peek_next_nonws(in);
if (c == '"') {
- in.get(c);
+ in.get();
READ_INTO(in, buf, 255, c, c != '"');
if (c == '"')
- in.get(c);
+ in.get();
else
throw_(amount_error, _("Quoted commodity symbol lacks closing quote"));
} else {
@@ -310,46 +310,45 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') {
std::size_t bytes = 0;
std::ptrdiff_t size = _p - buf;
- unsigned char d = static_cast<unsigned char>(c);
// Check for the start of a UTF-8 multi-byte encoded string
- if (d >= 192 && d <= 223 && size < 254)
+ if (c >= 192 && c <= 223 && size < 254)
bytes = 2;
- else if (d >= 224 && d <= 239 && size < 253)
+ else if (c >= 224 && c <= 239 && size < 253)
bytes = 3;
- else if (d >= 240 && d <= 247 && size < 252)
+ else if (c >= 240 && c <= 247 && size < 252)
bytes = 4;
- else if (d >= 248 && d <= 251 && size < 251)
+ else if (c >= 248 && c <= 251 && size < 251)
bytes = 5;
- else if (d >= 252 && d <= 253 && size < 250)
+ else if (c >= 252 && c <= 253 && size < 250)
bytes = 6;
- else if (d >= 254) // UTF-8 encoding error
+ else if (c >= 254) // UTF-8 encoding error
break;
if (bytes > 0) { // we're looking at a UTF-8 encoding
for (std::size_t i = 0; i < bytes; i++) {
- in.get(c);
+ c = in.get();
if (in.bad() || in.eof())
throw_(amount_error, _("Invalid UTF-8 encoding for commodity name"));
*_p++ = c;
}
}
- else if (invalid_chars[static_cast<unsigned char>(c)]) {
+ else if (invalid_chars[c]) {
break;
}
else {
- in.get(c);
+ c = in.get();
if (in.eof())
break;
if (c == '\\') {
- in.get(c);
+ c = in.get();
if (in.eof())
throw_(amount_error, _("Backslash at end of commodity name"));
}
*_p++ = c;
}
- c = static_cast<char>(in.peek());
+ c = in.peek();
}
*_p = '\0';