@@ -54,17 +54,11 @@ static bool php_phongo_utcdatetime_init_from_string(php_phongo_utcdatetime_t* in
5454 int64_t milliseconds ;
5555 char * endptr = NULL ;
5656
57- errno = 0 ;
57+ /* bson_ascii_strtoll() sets errno if conversion fails. If conversion
58+ * succeeds, we still want to ensure that the entire string was parsed. */
5859
5960 milliseconds = bson_ascii_strtoll (s_milliseconds , & endptr , 10 );
6061
61- /* errno will set errno if conversion fails; however, we do not need to
62- * specify the type of error.
63- *
64- * Note: bson_ascii_strtoll() does not properly detect out-of-range values
65- * (see: CDRIVER-1377). strtoll() would be preferable, but it is not
66- * available on all platforms (e.g. HP-UX), and atoll() provides no error
67- * reporting at all. */
6862 if (errno || (endptr && endptr != ((const char * ) s_milliseconds + s_milliseconds_len ))) {
6963 phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error parsing \"%s\" as 64-bit integer for %s initialization" , s_milliseconds , ZSTR_VAL (php_phongo_utcdatetime_ce -> name ));
7064 return false;
@@ -223,18 +217,18 @@ static PHP_METHOD(UTCDateTime, __set_state)
223217static PHP_METHOD (UTCDateTime , __toString )
224218{
225219 php_phongo_utcdatetime_t * intern ;
226- char * tmp ;
227- int tmp_len ;
220+ char s_milliseconds [ 24 ] ;
221+ int s_milliseconds_len ;
228222
229223 intern = Z_UTCDATETIME_OBJ_P (getThis ());
230224
231225 if (zend_parse_parameters_none () == FAILURE ) {
232226 return ;
233227 }
234228
235- tmp_len = spprintf ( & tmp , 0 , "%" PRId64 , intern -> milliseconds );
236- PHONGO_RETVAL_STRINGL ( tmp , tmp_len );
237- 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 );
238232} /* }}} */
239233
240234/* {{{ proto DateTime MongoDB\BSON\UTCDateTime::toDateTime()
0 commit comments