summaryrefslogtreecommitdiff
path: root/ext/json/json.c
diff options
context:
space:
mode:
authorAnthony Ferrara <ircmaxell@gmail.com>2012-07-10 10:33:51 -0400
committerAnthony Ferrara <ircmaxell@gmail.com>2012-07-10 10:33:51 -0400
commit99b7956ad58395853f7950ae01a43139413d348d (patch)
tree3380292c8bd8211390b768d1f7c5e958840d99ae /ext/json/json.c
parent9d3630b5dc8fa066dc4212ead2fffc8635f5bc0a (diff)
parentb210766084cbd00b0e479d2800e1920271a3faba (diff)
downloadphp-git-99b7956ad58395853f7950ae01a43139413d348d.tar.gz
Merge remote branch 'upstream/master' into hash_password
* upstream/master: (34 commits) Fixed Bug #62500 (Segfault in DateInterval class when extended) Fixed test bug #62312 (warnings changed one more time) fix valgrind warning fix valgrind warning fixed #62433 test for win update NEWS Fixed bug #62499 (curl_setopt($ch, CURLOPT_COOKIEFILE, "") returns false) appease MSVC (doesnt like unary minus of unsigned ints) appease MSVC (doesnt like unary minus of unsigned ints) appease MSVC (doesnt like unary minus of unsigned ints) - Fixed bug #62507 (['REQUEST_TIME'] under mod_php5 returns miliseconds instead of seconds) Fixed Bug #62500 (Segfault in DateInterval class when extended) Added in NEWS and UPGRADING for feature 55218 Fix two issues with run-tests.php Fix potential integer overflow in nl2br Fix potential integer overflow in bin2hex This wil be PHP 5.3.16 Revert change 3f3ad30c50: There shouldn't be new features in 5.3, especially not if they aren't in 5.4, too. fix (signed) integer overflow (part of bug #52550 fix (signed) integer overflow (part of bug #52550 ...
Diffstat (limited to 'ext/json/json.c')
-rw-r--r--ext/json/json.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index b467079610..96690477c9 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -311,7 +311,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
smart_str_appendc(buf, ':');
json_pretty_print_char(buf, options, ' ' TSRMLS_CC);
-
+
php_json_encode(buf, *data, options TSRMLS_CC);
} else {
if (need_comma) {
@@ -329,7 +329,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
smart_str_appendc(buf, ':');
json_pretty_print_char(buf, options, ' ' TSRMLS_CC);
-
+
php_json_encode(buf, *data, options TSRMLS_CC);
}
}
@@ -340,7 +340,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
}
}
}
-
+
--JSON_G(encoder_depth);
json_pretty_print_char(buf, options, '\n' TSRMLS_CC);
json_pretty_print_indent(buf, options TSRMLS_CC);
@@ -360,6 +360,7 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
int pos = 0, ulen = 0;
unsigned short us;
unsigned short *utf16;
+ size_t newlen;
if (len == 0) {
smart_str_appendl(buf, "\"\"", 2);
@@ -387,9 +388,9 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
}
return;
}
-
+
}
-
+
utf16 = (options & PHP_JSON_UNESCAPED_UNICODE) ? NULL : (unsigned short *) safe_emalloc(len, sizeof(unsigned short), 0);
ulen = utf8_to_utf16(utf16, s, len);
if (ulen <= 0) {
@@ -408,6 +409,8 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
len = ulen;
}
+ /* pre-allocate for string length plus 2 quotes */
+ smart_str_alloc(buf, len+2, 0);
smart_str_appendc(buf, '"');
while (pos < len)
@@ -520,13 +523,13 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio
zend_class_entry *ce = Z_OBJCE_P(val);
zval *retval = NULL, fname;
HashTable* myht;
-
+
if (Z_TYPE_P(val) == IS_ARRAY) {
myht = HASH_OF(val);
} else {
myht = Z_OBJPROP_P(val);
- }
-
+ }
+
if (myht && myht->nApplyCount > 1) {
JSON_G(error_code) = PHP_JSON_ERROR_RECURSION;
smart_str_appendl(buf, "null", 4);
@@ -539,7 +542,7 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Failed calling %s::jsonSerialize()", ce->name);
smart_str_appendl(buf, "null", sizeof("null") - 1);
return;
- }
+ }
if (EG(exception)) {
/* Error already raised */