Fix compiler warning type-limits in found_string (ref #2911) (#3263)

Whether `char` has a sign is implementation dependent, and `c >= 0` may
result in a compiler warning. We can use bitwise operator to check
whether the character is a control character, regardless of the sign.
This commit is contained in:
itchyny authored and GitHub committed 2025-02-18 07:52:58 +09:00
1 parent 6d8e9f98ae
commit 70e72abea3
2 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -493,7 +493,7 @@ static pfunc found_string(struct jv_parser* p) {
return "Invalid escape";
}
} else {
if (c >= 0 && c <= 0x001f)
if (!(c & ~0x1F))
return "Invalid string: control characters from U+0000 through U+001F must be escaped";
*out++ = c;
}