Skip to content

Commit cb1d0ca

Browse files
committed
fix hangup when json is closing more } than there are {
1 parent 2787c04 commit cb1d0ca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

NppJSONViewer/json.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,11 @@ char *
10371037
json_format_string (const char *text)
10381038
{
10391039
size_t pos = 0, text_length;
1040-
unsigned int indentation = 0; /* the current indentation level */
1041-
unsigned int i; /* loop iterator variable */
1040+
1041+
// make sure these two integers are signed
1042+
// we want to allow negative when the json is bad
1043+
signed int indentation = 0; /* the current indentation level */
1044+
signed int i; /* loop iterator variable */
10421045
char loop;
10431046

10441047
rcstring *output;
@@ -1069,6 +1072,9 @@ json_format_string (const char *text)
10691072
case '}':
10701073
indentation--;
10711074
rcs_catc (output, '\n');
1075+
// the for loop will compare i with potential negative values
1076+
// so we don't get caught in an infinite loop if the json is faulty with more "}" than "{"
1077+
// we just print out the same number of faulty "}" characters.
10721078
for (i = 0; i < indentation; i++)
10731079
{
10741080
rcs_catc (output, '\t');

0 commit comments

Comments
 (0)