Skip to content

Commit 72cf685

Browse files
committed
Merge pull request #857
2 parents 4a56dfe + ae98012 commit 72cf685

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/BSON/Timestamp.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,8 @@ static bool php_phongo_timestamp_init_from_string(php_phongo_timestamp_t* intern
6060
int64_t increment, timestamp;
6161
char* endptr = NULL;
6262

63-
errno = 0;
64-
65-
/* errno will set errno if conversion fails; however, we do not need to
66-
* specify the type of error.
67-
*
68-
* Note: bson_ascii_strtoll() does not properly detect out-of-range values
69-
* (see: CDRIVER-1377). strtoll() would be preferable, but it is not
70-
* available on all platforms (e.g. HP-UX), and atoll() provides no error
71-
* reporting at all. */
63+
/* bson_ascii_strtoll() sets errno if conversion fails. If conversion
64+
* succeeds, we still want to ensure that the entire string was parsed. */
7265

7366
increment = bson_ascii_strtoll(s_increment, &endptr, 10);
7467

src/BSON/UTCDateTime.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
223217
static 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

Comments
 (0)