-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for trailing garbage inside json #80
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many formatting/spacing changes that make it difficult to see the actual changed code. Would you be willing to try again without reformatting the source file?
@tmegow Could you perhaps discard the indentation and formatting commits? Then, commit Allow for empty objects and empty arrays must be reworked to only bring essential changes. I'm not saying the current format is perfect, but reformatting everything while adding actual changes is never an option. |
json.h
Outdated
@@ -266,6 +266,7 @@ json_value * json_parse_ex (json_settings * settings, | |||
|
|||
void json_value_free (json_value *); | |||
|
|||
int trailing_garbage (const json_char *); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this function need to be declared in json.h
? I don't think so, it should be a static function of json.c
.
json.c
Outdated
case '"': | ||
return 0; | ||
|
||
case 'e': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're looking for "false"
Perhaps a strncmp()
would be more readable. At least add a comment, like /* skipping "false" */
or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then would strncmp()
work for all possible types of json_char
?
json.c
Outdated
marker = *(--ptr); | ||
if (marker == 's') | ||
{ | ||
if (*(--ptr) == 'l' && *(--ptr) == 'a' && *(--ptr) == 'f') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you decrement --ptr
multiple times. Are there cases where you could decrement past the beginning of the buffer?
json.c
Outdated
return 0; | ||
} | ||
} | ||
if (marker == 'u') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're looking for "true"
Perhaps a strncmp()
would be more readable. At least add a comment, like /* skipping "true" */
or something similar.
json.c
Outdated
} | ||
if (marker == 'u') | ||
{ | ||
if (*(--ptr) == 'r' && *(--ptr) == 't') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about multiple --ptr
.
json.c
Outdated
|
||
return 1; | ||
|
||
case 'l': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're looking for "null"
Perhaps a strncmp()
would be more readable. At least add a comment, like /* skipping "null" */
or something similar.
json.c
Outdated
return 1; | ||
|
||
case 'l': | ||
if (*(--ptr) == 'l' && *(--ptr) == 'u' && *(--ptr) == 'n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about multiple --ptr
.
A stab at addressing open issue #73