Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions NppJSONViewer/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,11 @@ char *
json_format_string (const char *text)
{
size_t pos = 0, text_length;
unsigned int indentation = 0; /* the current indentation level */
unsigned int i; /* loop iterator variable */

// make sure these two integers are signed
// we want to allow testing against negative when the json is bad
signed int indentation = 0; /* the current indentation level */
signed int i; /* loop iterator variable */
char loop;

rcstring *output;
Expand Down Expand Up @@ -1069,6 +1072,9 @@ json_format_string (const char *text)
case '}':
indentation--;
rcs_catc (output, '\n');
// the for loop will compare i with potential negative values
// so we don't get caught in an infinite loop if the json is faulty with more "}" than "{"
// we just print out the same number of faulty "}" characters.
for (i = 0; i < indentation; i++)
{
rcs_catc (output, '\t');
Expand Down Expand Up @@ -1101,11 +1107,6 @@ json_format_string (const char *text)
{
rcs_catc (output, '\\');
pos++;
if (text[pos] == '\"') /* don't consider a \" escaped sequence as an end of string */
{
rcs_catc (output, '\"');
pos++;
}
}
else if (text[pos] == '\"') /* reached end of string */
{
Expand Down