-
Notifications
You must be signed in to change notification settings - Fork 7.9k
json_last_error_msg - better message - error position near by #18866
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
base: master
Are you sure you want to change the base?
json_last_error_msg - better message - error position near by #18866
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.
A few code style issues
Co-authored-by: DanielEScherzer <daniel.e.scherzer@gmail.com>
spprintf(&final_message, 0, "%s near character %zu", error_message, JSON_G(error_pos)); | ||
break; | ||
default: | ||
spprintf(&final_message, 0, "%s", error_message); |
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.
Printing to a formatting string like this seems a bit odd - you're just duplicating the message. Can you do a variable assignment instead?
@@ -339,7 +349,7 @@ PHP_JSON_API void php_json_parser_init_ex(php_json_parser *parser, | |||
int options, | |||
int max_depth, | |||
const php_json_parser_methods *parser_methods) | |||
{ | |||
{ |
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.
{ | |
{ |
s->cursor = (php_json_ctype *) str; | ||
s->limit = (php_json_ctype *) str + str_len; | ||
s->options = options; | ||
s->errpos = 0; | ||
s->errcode = 0; |
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.
You shouldn't initialize these values twice - errpos is set to 0 above, and errcode is set to PHP_JSON_ERROR_NONE which is also 0, so these two lines can just be removed
Working POC giving a better error message when the
json_last_error_msg
function is called (only for this function).Adding near character %d to a json related error message.
Putting aside my bad C coding skill, I would like to know your opinions on this PR, and kindly ask for reviews in order to improve it.
Thx in advance.
(@bukka I know you have been working on a new parser, but ... until that reaches the surface, could we go this way? (with the proper adjustments for sure)