8000 json_last_error_msg - better message - error position near by by juan-morales · Pull Request #18866 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
POC
  • Loading branch information
juan-morales committed Jun 12, 2025
commit 73a671edbe7e2f11e42c5ed19fbea824e40187e0
8000
16 changes: 8 additions & 8 deletions ext/json/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ static const char *php_json_get_error_msg(php_json_error_code error_code) /* {{{
case PHP_JSON_ERROR_CTRL_CHAR:
return "Control character error, possibly incorrectly encoded";
case PHP_JSON_ERROR_SYNTAX:
char *msg;
spprintf(&msg, 0, "Syntax error near character %zu", JSON_G(error_pos));
return msg;
return "Syntax error";
case PHP_JSON_ERROR_UTF8:
return "Malformed UTF-8 characters, possibly incorrectly encoded";
case PHP_JSON_ERROR_RECURSION:
Expand Down Expand Up @@ -375,11 +373,13 @@ PHP_FUNCTION(json_last_error_msg)
{
ZEND_PARSE_PARAMETERS_NONE();

char *msg = php_json_get_error_msg(JSON_G(error_code));
RETVAL_STRING(msg);
if (JSON_G(error_code) == PHP_JSON_ERROR_SYNTAX) {
efree(msg);
}
//original:RETURN_STRING(php_json_get_error_msg(JSON_G(error_code)));
char *msg;
spprintf(&msg, 0, "Syntax error near character %zu", JSON_G(error_pos));
RETVAL_STRING(msg);
efree(msg);
} else {
RETURN_STRING(php_json_get_error_msg(JSON_G(error_code)));
}
}
/* }}} */
0