Skip to content

Commit bb1d870

Browse files
committed
Merge pull request #6 from vancekic/fix
Fix #5 Notepad hanging with faulty json
2 parents 5709ffa + 99992c5 commit bb1d870

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

NppJSONViewer/json.c

Lines changed: 8 additions & 7 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 testing against 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');
@@ -1101,11 +1107,6 @@ json_format_string (const char *text)
11011107
{
11021108
rcs_catc (output, '\\');
11031109
pos++;
1104-
if (text[pos] == '\"') /* don't consider a \" escaped sequence as an end of string */
1105-
{
1106-
rcs_catc (output, '\"');
1107-
pos++;
1108-
}
11091110
}
11101111
else if (text[pos] == '\"') /* reached end of string */
11111112
{

0 commit comments

Comments
 (0)