@@ -311,7 +311,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
311
311
smart_str_appendc (buf , ':' );
312
312
313
313
json_pretty_print_char (buf , options , ' ' TSRMLS_CC );
314
-
314
+
315
315
php_json_encode (buf , * data , options TSRMLS_CC );
316
316
} else {
317
317
if (need_comma ) {
@@ -329,7 +329,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
329
329
smart_str_appendc (buf , ':' );
330
330
331
331
json_pretty_print_char (buf , options , ' ' TSRMLS_CC );
332
-
332
+
333
333
php_json_encode (buf , * data , options TSRMLS_CC );
334
334
}
335
335
}
@@ -340,7 +340,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
340
340
}
341
341
}
342
342
}
343
-
343
+
344
344
-- JSON_G (encoder_depth );
345
345
json_pretty_print_char (buf , options , '\n' TSRMLS_CC );
346
346
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
360
360
int pos = 0 , ulen = 0 ;
361
361
unsigned short us ;
362
362
unsigned short * utf16 ;
363
+ size_t newlen ;
363
364
364
365
if (len == 0 ) {
365
366
smart_str_appendl (buf , "\"\"" , 2 );
@@ -387,9 +388,9 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
387
388
}
388
389
return ;
389
390
}
390
-
391
+
391
392
}
392
-
393
+
393
394
utf16 = (options & PHP_JSON_UNESCAPED_UNICODE ) ? NULL : (unsigned short * ) safe_emalloc (len , sizeof (unsigned short ), 0 );
394
395
ulen = utf8_to_utf16 (utf16 , s , len );
395
396
if (ulen <= 0 ) {
@@ -408,6 +409,8 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
408
409
len = ulen ;
409
410
}
410
411
412
+ /* pre-allocate for string length plus 2 quotes */
413
+ smart_str_alloc (buf , len + 2 , 0 );
411
414
smart_str_appendc (buf , '"' );
412
415
413
416
while (pos < len )
@@ -520,13 +523,13 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio
520
523
zend_class_entry * ce = Z_OBJCE_P (val );
521
524
zval * retval = NULL , fname ;
522
525
HashTable * myht ;
523
-
526
+
524
527
if (Z_TYPE_P (val ) == IS_ARRAY ) {
525
528
myht = HASH_OF (val );
526
529
} else {
527
530
myht = Z_OBJPROP_P (val );
528
- }
529
-
531
+ }
532
+
530
533
if (myht && myht -> nApplyCount > 1 ) {
531
534
JSON_G (error_code ) = PHP_JSON_ERROR_RECURSION ;
532
535
smart_str_appendl (buf , "null" , 4 );
@@ -539,7 +542,7 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio
539
542
zend_throw_exception_ex (NULL , 0 TSRMLS_CC , "Failed calling %s::jsonSerialize()" , ce -> name );
540
543
smart_str_appendl (buf , "null" , sizeof ("null" ) - 1 );
541
544
return ;
542
- }
545
+ }
543
546
544
547
if (EG (exception )) {
545
548
/* Error already raised */
0 commit comments