Skip to content

Commit e584ee8

Browse files
committed
Update bson_ascii_strtoll() usage in Timestamp and UTCDateTime
bson_ascii_strtoll() resets errno, so that is no longer necessary. This also removes some outdated comments.
1 parent 4a56dfe commit e584ee8

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
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: 2 additions & 8 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;

0 commit comments

Comments
 (0)