From df7f9e0b2cc8e4cfd018ef2d0327a69345bb48f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 Nov 2018 14:50:07 +0100 Subject: [PATCH] basic/json: silence gcc warning about limited range of data type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With gcc-7.1.1-3.fc26.aarch64: ../src/basic/json.c: In function ‘json_format’: ../src/basic/json.c:1409:40: warning: comparison is always true due to limited range of data type [-Wtype-limits] if (*q >= 0 && *q < ' ') ^~ ../src/basic/json.c: In function ‘inc_lines_columns’: ../src/basic/json.c:1762:31: warning: comparison is always true due to limited range of data type [-Wtype-limits] } else if (*s >= 0 && *s < 127) /* Process ASCII chars quickly */ ^~ Cast to (signed char) silences the warning, but a cast to (int) for some reason doesn't. --- src/basic/json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/basic/json.c b/src/basic/json.c index 53ac80a6c6..eec6ea7baf 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -1406,7 +1406,7 @@ static int json_format(FILE *f, JsonVariant *v, unsigned flags, const char *pref break; default: - if (*q >= 0 && *q < ' ') + if ((signed char) *q >= 0 && *q < ' ') fprintf(f, "\\u%04x", *q); else fputc(*q, f); @@ -1759,7 +1759,7 @@ static void inc_lines_columns(unsigned *line, unsigned *column, const char *s, s if (*s == '\n') { (*line)++; *column = 1; - } else if (*s >= 0 && *s < 127) /* Process ASCII chars quickly */ + } else if ((signed char) *s >= 0 && *s < 127) /* Process ASCII chars quickly */ (*column)++; else { int w;