Skip to content

Commit ae98012

Browse files
committed
Use static string buffer for UTCDateTime::__toString()
1 parent e584ee8 commit ae98012

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/BSON/UTCDateTime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,18 @@ static PHP_METHOD(UTCDateTime, __set_state)
217217
static PHP_METHOD(UTCDateTime, __toString)
218218
{
219219
php_phongo_utcdatetime_t* intern;
220-
char* tmp;
221-
int tmp_len;
220+
char s_milliseconds[24];
221+
int s_milliseconds_len;
222222

223223
intern = Z_UTCDATETIME_OBJ_P(getThis());
224224

225225
if (zend_parse_parameters_none() == FAILURE) {
226226
return;
227227
}
228228

229-
tmp_len = spprintf(&tmp, 0, "%" PRId64, intern->milliseconds);
230-
PHONGO_RETVAL_STRINGL(tmp, tmp_len);
231-
efree(tmp);
229+
s_milliseconds_len = snprintf(s_milliseconds, sizeof(s_milliseconds), "%" PRId64, intern->milliseconds);
230+
231+
PHONGO_RETVAL_STRINGL(s_milliseconds, s_milliseconds_len);
232232
} /* }}} */
233233

234234
/* {{{ proto DateTime MongoDB\BSON\UTCDateTime::toDateTime()

0 commit comments

Comments
 (0)