lib: json: use explicit unsigned char to avoid array subscript error

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)])

Being explicit about the char being unsigned char deals with this.

Change-Id: If2416218220ef5b29f1a69470cbcc6b4fd49ef86
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2017-04-14 10:48:42 -05:00 committed by Anas Nashif
commit 21309ea44b

View file

@ -24,9 +24,9 @@ struct token {
struct lexer {
void *(*state)(struct lexer *lexer);
char *start;
char *pos;
char *end;
unsigned char *start;
unsigned char *pos;
unsigned char *end;
struct token token;
};
@ -76,7 +76,7 @@ static void emit(struct lexer *lexer, enum json_tokens token)
lexer->start = lexer->pos;
}
static char next(struct lexer *lexer)
static unsigned char next(struct lexer *lexer)
{
if (lexer->pos >= lexer->end) {
lexer->pos = lexer->end + 1;
@ -97,9 +97,9 @@ static void backup(struct lexer *lexer)
lexer->pos--;
}
static char peek(struct lexer *lexer)
static unsigned char peek(struct lexer *lexer)
{
char chr = next(lexer);
unsigned char chr = next(lexer);
backup(lexer);
@ -111,7 +111,7 @@ static void *lexer_string(struct lexer *lexer)
ignore(lexer);
while (true) {
char chr = next(lexer);
unsigned char chr = next(lexer);
if (chr == '\0') {
emit(lexer, JSON_TOK_ERROR);
@ -216,7 +216,7 @@ static void *lexer_null(struct lexer *lexer)
static void *lexer_number(struct lexer *lexer)
{
while (true) {
char chr = next(lexer);
unsigned char chr = next(lexer);
if (isdigit(chr) || chr == '.') {
continue;
@ -232,7 +232,7 @@ static void *lexer_number(struct lexer *lexer)
static void *lexer_json(struct lexer *lexer)
{
while (true) {
char chr = next(lexer);
unsigned char chr = next(lexer);
switch (chr) {
case '\0':