Skip to content

Commit 3849719

Browse files
committed
Merged pull request #435
2 parents 391a110 + eb35da1 commit 3849719

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/BSON/Timestamp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ zend_object_handlers php_phongo_handler_timestamp;
5454

5555
/* Initialize the object and return whether it was successful. An exception will
5656
* be thrown on error. */
57-
static bool php_phongo_timestamp_init(php_phongo_timestamp_t *intern, phongo_long increment, phongo_long timestamp TSRMLS_DC)
57+
static bool php_phongo_timestamp_init(php_phongo_timestamp_t *intern, int64_t increment, int64_t timestamp TSRMLS_DC)
5858
{
5959
if (increment < 0 || increment > UINT32_MAX) {
6060
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected increment to be an unsigned 32-bit integer, %" PHONGO_LONG_FORMAT " given", increment);
@@ -66,8 +66,8 @@ static bool php_phongo_timestamp_init(php_phongo_timestamp_t *intern, phongo_lon
6666
return false;
6767
}
6868

69-
intern->increment = increment;
70-
intern->timestamp = timestamp;
69+
intern->increment = (uint32_t) increment;
70+
intern->timestamp = (uint32_t) timestamp;
7171
intern->initialized = true;
7272

7373
return true;
@@ -413,8 +413,8 @@ HashTable *php_phongo_timestamp_get_properties(zval *object TSRMLS_DC) /* {{{ */
413413
return props;
414414
}
415415

416-
s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRId64, intern->increment);
417-
s_timestamp_len = snprintf(s_timestamp, sizeof(s_timestamp), "%" PRId64, intern->timestamp);
416+
s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment);
417+
s_timestamp_len = snprintf(s_timestamp, sizeof(s_timestamp), "%" PRIu32, intern->timestamp);
418418

419419
#if PHP_VERSION_ID >= 70000
420420
{

tests/bson/bson-timestamp-set_state_error-002.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ echo throws(function() {
1010
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1111

1212
echo throws(function() {
13-
MongoDB\BSON\Timestamp::__set_state(['increment' => -2147483648, 'timestamp' => 5678]);
13+
MongoDB\BSON\Timestamp::__set_state(['increment' => -2147483647, 'timestamp' => 5678]);
1414
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1515

1616
echo throws(function() {
1717
MongoDB\BSON\Timestamp::__set_state(['increment' => 1234, 'timestamp' => -1]);
1818
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1919

2020
echo throws(function() {
21-
MongoDB\BSON\Timestamp::__set_state(['increment' => 1234, 'timestamp' => -2147483648]);
21+
MongoDB\BSON\Timestamp::__set_state(['increment' => 1234, 'timestamp' => -2147483647]);
2222
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
2323

2424
?>
@@ -28,9 +28,9 @@ echo throws(function() {
2828
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
2929
Expected increment to be an unsigned 32-bit integer, -1 given
3030
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31-
Expected increment to be an unsigned 32-bit integer, -2147483648 given
31+
Expected increment to be an unsigned 32-bit integer, -2147483647 given
3232
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
3333
Expected timestamp to be an unsigned 32-bit integer, -1 given
3434
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35-
Expected timestamp to be an unsigned 32-bit integer, -2147483648 given
35+
Expected timestamp to be an unsigned 32-bit integer, -2147483647 given
3636
===DONE===

tests/bson/bug0592.phpt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ foreach ($tests as $json) {
3232
===DONE===
3333
<?php exit(0); ?>
3434
--EXPECTF--
35+
%a
3536
Test { "x": { "$numberLong": "-2147483648" }}
3637
object(stdClass)#%d (%d) {
3738
["x"]=>
@@ -44,15 +45,22 @@ object(stdClass)#%d (%d) {
4445
int(2147483647)
4546
}
4647

48+
Test { "x": { "$numberLong": "4294967294" }}
49+
[%s] PHONGO-BSON: WARNING > Integer overflow detected on your platform: 4294967294
50+
object(stdClass)#%d (%d) {
51+
["x"]=>
52+
string(10) "4294967294"
53+
}
54+
4755
Test { "x": { "$numberLong": "4294967295" }}
48-
[%s] PHONGO-BSON: WARNING > ENTRY: Integer overflow detected on your platform: 4294967295
56+
[%s] PHONGO-BSON: WARNING > Integer overflow detected on your platform: 4294967295
4957
object(stdClass)#%d (%d) {
5058
["x"]=>
5159
string(10) "4294967295"
5260
}
5361

5462
Test { "x": { "$numberLong": "9223372036854775807" }}
55-
[%s] PHONGO-BSON: WARNING > ENTRY: Integer overflow detected on your platform: 9223372036854775807
63+
[%s] PHONGO-BSON: WARNING > Integer overflow detected on your platform: 9223372036854775807
5664
object(stdClass)#%d (%d) {
5765
["x"]=>
5866
string(19) "9223372036854775807"
@@ -71,20 +79,21 @@ object(stdClass)#%d (%d) {
7179
}
7280

7381
Test { "longFieldName": { "$numberLong": "4294967294" }}
82+
[%s] PHONGO-BSON: WARNING > Integer overflow detected on your platform: 4294967294
7483
object(stdClass)#%d (%d) {
7584
["longFieldName"]=>
7685
string(10) "4294967294"
7786
}
7887

7988
Test { "longFieldName": { "$numberLong": "4294967295" }}
80-
[%s] PHONGO-BSON: WARNING > ENTRY: Integer overflow detected on your platform: 4294967295
89+
[%s] PHONGO-BSON: WARNING > Integer overflow detected on your platform: 4294967295
8190
object(stdClass)#%d (%d) {
8291
["longFieldName"]=>
8392
string(10) "4294967295"
8493
}
8594

8695
Test { "longFieldName": { "$numberLong": "9223372036854775807" }}
87-
[%s] PHONGO-BSON: WARNING > ENTRY: Integer overflow detected on your platform: 9223372036854775807
96+
[%s] PHONGO-BSON: WARNING > Integer overflow detected on your platform: 9223372036854775807
8897
object(stdClass)#%d (%d) {
8998
["longFieldName"]=>
9099
string(19) "9223372036854775807"

0 commit comments

Comments
 (0)