Skip to content

Commit aca302d

Browse files
committed
Handle unsigned versus signed char comparisons
Fixes these warnings: ../../submodules/loguru/loguru.cpp:559:15: warning: comparison is always true due to limited range of data type [-Wtype-limits] else if (0 <= c && c < 0x20) { // ASCI control character: ~~^~~~ ../../submodules/loguru/loguru.cpp: In function ‘loguru::Text loguru::ec_to_text(char)’: ../../submodules/loguru/loguru.cpp:1776:14: warning: comparison is always true due to limited range of data type [-Wtype-limits] else if (0 <= c && c < 0x20) { ~~^~~~
1 parent 1c2f98a commit aca302d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

loguru.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <cstdio>
4141
#include <cstdlib>
4242
#include <cstring>
43+
#include <climits>
4344
#include <mutex>
4445
#include <regex>
4546
#include <string>
@@ -556,7 +557,11 @@ namespace loguru
556557
else if (c == '\'') { out += "\\\'"; }
557558
else if (c == '\"') { out += "\\\""; }
558559
else if (c == ' ') { out += "\\ "; }
559-
else if (0 <= c && c < 0x20) { // ASCI control character:
560+
#if (CHAR_MIN < 0) // char is signed
561+
else if (0 <= c && c < 0x20) { // ASCI control character
562+
#else // char is unsigned
563+
else if (c < 0x20) { // ASCI control character
564+
#endif
560565
// else if (c < 0x20 || c != (c & 127)) { // ASCII control character or UTF-8:
561566
out += "\\x";
562567
write_hex_byte(out, static_cast<uint8_t>(c));
@@ -1773,7 +1778,11 @@ namespace loguru
17731778
else if (c == '\n') { str += "\\n"; }
17741779
else if (c == '\r') { str += "\\r"; }
17751780
else if (c == '\t') { str += "\\t"; }
1781+
#if (CHAR_MIN < 0) // char is signed
17761782
else if (0 <= c && c < 0x20) {
1783+
#else // char is unsigned
1784+
else if (c < 0x20) {
1785+
#endif
17771786
str += "\\u";
17781787
write_hex_16(static_cast<uint16_t>(c));
17791788
} else { str += c; }

0 commit comments

Comments
 (0)