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:
parent
4c80a2fb71
commit
21309ea44b
1 changed files with 9 additions and 9 deletions
|
@ -24,9 +24,9 @@ struct token {
|
||||||
|
|
||||||
struct lexer {
|
struct lexer {
|
||||||
void *(*state)(struct lexer *lexer);
|
void *(*state)(struct lexer *lexer);
|
||||||
char *start;
|
unsigned char *start;
|
||||||
char *pos;
|
unsigned char *pos;
|
||||||
char *end;
|
unsigned char *end;
|
||||||
struct token token;
|
struct token token;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,7 +76,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 unsigned char next(struct lexer *lexer)
|
||||||
{
|
{
|
||||||
if (lexer->pos >= lexer->end) {
|
if (lexer->pos >= lexer->end) {
|
||||||
lexer->pos = lexer->end + 1;
|
lexer->pos = lexer->end + 1;
|
||||||
|
@ -97,9 +97,9 @@ static void backup(struct lexer *lexer)
|
||||||
lexer->pos--;
|
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);
|
backup(lexer);
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ static void *lexer_string(struct lexer *lexer)
|
||||||
ignore(lexer);
|
ignore(lexer);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
char chr = next(lexer);
|
unsigned char chr = next(lexer);
|
||||||
|
|
||||||
if (chr == '\0') {
|
if (chr == '\0') {
|
||||||
emit(lexer, JSON_TOK_ERROR);
|
emit(lexer, JSON_TOK_ERROR);
|
||||||
|
@ -216,7 +216,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);
|
unsigned char chr = next(lexer);
|
||||||
|
|
||||||
if (isdigit(chr) || chr == '.') {
|
if (isdigit(chr) || chr == '.') {
|
||||||
continue;
|
continue;
|
||||||
|
@ -232,7 +232,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);
|
unsigned char chr = next(lexer);
|
||||||
|
|
||||||
switch (chr) {
|
switch (chr) {
|
||||||
case '\0':
|
case '\0':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue