diff options
author | kanreki <32443233+kanreki@users.noreply.github.com> | 2021-09-14 12:15:53 -0700 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2021-12-08 16:17:17 -0800 |
commit | 586abd208221761a6c93bc4568513e9cd4dc287d (patch) | |
tree | d3d6c8da7e4584665bb705c25a91c5c66083de65 /src/utils.h | |
parent | ed5886921bcce0d1a261a37aa83bf135259b7d21 (diff) | |
download | fork-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/utils.h')
-rw-r--r-- | src/utils.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/utils.h b/src/utils.h index c9146dd7..9af1251a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -540,25 +540,25 @@ inline char * next_element(char * buf, bool variable = false) { return NULL; } -inline char peek_next_nonws(std::istream& in) { - char c = static_cast<char>(in.peek()); +inline int peek_next_nonws(std::istream& in) { + int c = in.peek(); while (in.good() && ! in.eof() && std::isspace(c)) { - in.get(c); - c = static_cast<char>(in.peek()); + in.get(); + c = in.peek(); } return c; } #define READ_INTO(str, targ, size, var, cond) { \ char * _p = targ; \ - var = static_cast<char>(str.peek()); \ + var = str.peek(); \ while (str.good() && ! str.eof() && var != '\n' && \ (cond) && _p - targ < size) { \ - str.get(var); \ + var = str.get(); \ if (str.eof()) \ break; \ if (var == '\\') { \ - str.get(var); \ + var = str.get(); \ if (in.eof()) \ break; \ switch (var) { \ @@ -572,22 +572,22 @@ inline char peek_next_nonws(std::istream& in) { } \ } \ *_p++ = var; \ - var = static_cast<char>(str.peek()); \ + var = str.peek(); \ } \ *_p = '\0'; \ } #define READ_INTO_(str, targ, size, var, idx, cond) { \ char * _p = targ; \ - var = static_cast<char>(str.peek()); \ + var = str.peek(); \ while (str.good() && ! str.eof() && var != '\n' && \ (cond) && _p - targ < size) { \ - str.get(var); \ + var = str.get(); \ if (str.eof()) \ break; \ idx++; \ if (var == '\\') { \ - str.get(var); \ + var = str.get(); \ if (in.eof()) \ break; \ switch (var) { \ @@ -602,7 +602,7 @@ inline char peek_next_nonws(std::istream& in) { idx++; \ } \ *_p++ = var; \ - var = static_cast<char>(str.peek()); \ + var = str.peek(); \ } \ *_p = '\0'; \ } |