Skip to content

Commit 3b3f6de

Browse files
committed
Use zend_string_concat3 in one place
A bit nicer than snprintf + passing the same length around three times.
1 parent 06e8ed5 commit 3b3f6de

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ext/date/php_date.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,11 +2522,11 @@ static bool php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myh
25222522
switch (Z_LVAL_P(z_timezone_type)) {
25232523
case TIMELIB_ZONETYPE_OFFSET:
25242524
case TIMELIB_ZONETYPE_ABBR: {
2525-
char *tmp = emalloc(Z_STRLEN_P(z_date) + Z_STRLEN_P(z_timezone) + 2);
2526-
int ret;
2527-
snprintf(tmp, Z_STRLEN_P(z_date) + Z_STRLEN_P(z_timezone) + 2, "%s %s", Z_STRVAL_P(z_date), Z_STRVAL_P(z_timezone));
2528-
ret = php_date_initialize(*dateobj, tmp, Z_STRLEN_P(z_date) + Z_STRLEN_P(z_timezone) + 1, NULL, NULL, 0);
2529-
efree(tmp);
2525+
zend_string *tmp = zend_string_concat3(
2526+
Z_STRVAL_P(z_date), Z_STRLEN_P(z_date), " ", 1,
2527+
Z_STRVAL_P(z_timezone), Z_STRLEN_P(z_timezone));
2528+
int ret = php_date_initialize(*dateobj, ZSTR_VAL(tmp), ZSTR_LEN(tmp), NULL, NULL, 0);
2529+
zend_string_release(tmp);
25302530
return 1 == ret;
25312531
}
25322532

0 commit comments

Comments
 (0)