From 586abd208221761a6c93bc4568513e9cd4dc287d Mon Sep 17 00:00:00 2001 From: kanreki <32443233+kanreki@users.noreply.github.com> Date: Tue, 14 Sep 2021 12:15:53 -0700 Subject: 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. --- src/utils.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/utils.h') 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(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(in.peek()); + in.get(); + c = in.peek(); } return c; } #define READ_INTO(str, targ, size, var, cond) { \ char * _p = targ; \ - var = static_cast(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(str.peek()); \ + var = str.peek(); \ } \ *_p = '\0'; \ } #define READ_INTO_(str, targ, size, var, idx, cond) { \ char * _p = targ; \ - var = static_cast(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(str.peek()); \ + var = str.peek(); \ } \ *_p = '\0'; \ } -- cgit v1.2.3