Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LB-- authored and DimitriPapadopoulos committed Aug 28, 2021
4 parents adc5915 + a8334dc + fab533e + 3b2c9fe commit 74e7813
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
30 changes: 16 additions & 14 deletions json.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ json_value * json_parse_ex (json_settings * settings,
size_t length,
char * error_buf)
{
json_char error [json_error_max];
char error [json_error_max];
const json_char * end;
json_value * top, * root, * alloc = 0;
json_state state = { 0 };
Expand Down Expand Up @@ -294,7 +294,7 @@ json_value * json_parse_ex (json_settings * settings,
if (flags & flag_string)
{
if (!b)
{ sprintf (error, "Unexpected EOF in string (at %u:%u)", line_and_col);
{ sprintf (error, "%u:%u: Unexpected EOF in string", line_and_col);
goto e_failed;
}

Expand All @@ -320,7 +320,7 @@ json_value * json_parse_ex (json_settings * settings,
(uc_b3 = hex_value (*++ state.ptr)) == 0xFF ||
(uc_b4 = hex_value (*++ state.ptr)) == 0xFF)
{
sprintf (error, "Invalid character value `%c` (at %u:%u)", b, line_and_col);
sprintf (error, "%u:%u: Invalid character value `%c`", line_and_col, b);
goto e_failed;
}

Expand All @@ -337,7 +337,7 @@ json_value * json_parse_ex (json_settings * settings,
(uc_b3 = hex_value (*++ state.ptr)) == 0xFF ||
(uc_b4 = hex_value (*++ state.ptr)) == 0xFF)
{
sprintf (error, "Invalid character value `%c` (at %u:%u)", b, line_and_col);
sprintf (error, "%u:%u: Invalid character value `%c`", line_and_col, b);
goto e_failed;
}

Expand Down Expand Up @@ -521,7 +521,7 @@ json_value * json_parse_ex (json_settings * settings,
default:

sprintf (error, "%u:%u: Trailing garbage: `%c`",
state.cur_line, state.cur_col, b);
line_and_col, b);

goto e_failed;
};
Expand All @@ -539,7 +539,7 @@ json_value * json_parse_ex (json_settings * settings,
if (top && top->type == json_array)
flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next;
else
{ sprintf (error, "%u:%u: Unexpected ]", line_and_col);
{ sprintf (error, "%u:%u: Unexpected `]`", line_and_col);
goto e_failed;
}

Expand All @@ -555,8 +555,8 @@ json_value * json_parse_ex (json_settings * settings,
}
else
{
sprintf (error, "%u:%u: Expected , before %c",
state.cur_line, state.cur_col, b);
sprintf (error, "%u:%u: Expected `,` before `%c`",
line_and_col, b);

goto e_failed;
}
Expand All @@ -570,8 +570,8 @@ json_value * json_parse_ex (json_settings * settings,
}
else
{
sprintf (error, "%u:%u: Expected : before %c",
state.cur_line, state.cur_col, b);
sprintf (error, "%u:%u: Expected `:` before `%c`",
line_and_col, b);

goto e_failed;
}
Expand Down Expand Up @@ -696,7 +696,7 @@ json_value * json_parse_ex (json_settings * settings,
continue;
}
else
{ sprintf (error, "%u:%u: Unexpected %c when seeking value", line_and_col, b);
{ sprintf (error, "%u:%u: Unexpected `%c` when seeking value", line_and_col, b);
goto e_failed;
}
};
Expand All @@ -716,7 +716,7 @@ json_value * json_parse_ex (json_settings * settings,
case '"':

if (flags & flag_need_comma)
{ sprintf (error, "%u:%u: Expected , before \"", line_and_col);
{ sprintf (error, "%u:%u: Expected `,` before `\"`", line_and_col);
goto e_failed;
}

Expand Down Expand Up @@ -774,10 +774,12 @@ json_value * json_parse_ex (json_settings * settings,
}

if (would_overflow(top->u.integer, b))
{ -- num_digits;
{
json_int_t integer = top->u.integer;
-- num_digits;
-- state.ptr;
top->type = json_double;
top->u.dbl = (double)top->u.integer;
top->u.dbl = (double)integer;
continue;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/valid-0013.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"French": "français",
"Greek": "ελληνικά",
"Korean": "한국말",
}

0 comments on commit 74e7813

Please sign in to comment.