lib: json: Fix warning when building with newlib

If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2018-07-11 15:24:11 -05:00 committed by Kumar Gala
commit 9aebe8b466

View file

@ -77,7 +77,7 @@ static void emit(struct lexer *lexer, enum json_tokens token)
lexer->start = lexer->pos; lexer->start = lexer->pos;
} }
static char next(struct lexer *lexer) static int next(struct lexer *lexer)
{ {
if (lexer->pos >= lexer->end) { if (lexer->pos >= lexer->end) {
lexer->pos = lexer->end + 1; lexer->pos = lexer->end + 1;
@ -98,9 +98,9 @@ static void backup(struct lexer *lexer)
lexer->pos--; lexer->pos--;
} }
static char peek(struct lexer *lexer) static int peek(struct lexer *lexer)
{ {
char chr = next(lexer); int chr = next(lexer);
backup(lexer); backup(lexer);
@ -112,7 +112,7 @@ static void *lexer_string(struct lexer *lexer)
ignore(lexer); ignore(lexer);
while (true) { while (true) {
char chr = next(lexer); int chr = next(lexer);
if (chr == '\0') { if (chr == '\0') {
emit(lexer, JSON_TOK_ERROR); emit(lexer, JSON_TOK_ERROR);
@ -217,7 +217,7 @@ static void *lexer_null(struct lexer *lexer)
static void *lexer_number(struct lexer *lexer) static void *lexer_number(struct lexer *lexer)
{ {
while (true) { while (true) {
char chr = next(lexer); int chr = next(lexer);
if (isdigit(chr) || chr == '.') { if (isdigit(chr) || chr == '.') {
continue; continue;
@ -233,7 +233,7 @@ static void *lexer_number(struct lexer *lexer)
static void *lexer_json(struct lexer *lexer) static void *lexer_json(struct lexer *lexer)
{ {
while (true) { while (true) {
char chr = next(lexer); int chr = next(lexer);
switch (chr) { switch (chr) {
case '\0': case '\0':