Skip to content

Commit f5edbe2

Browse files
committed
Merge pull request #241
2 parents 6aaa45d + f1c7be8 commit f5edbe2

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

src/BSON/UTCDateTime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PHP_METHOD(UTCDateTime, __construct)
5555
long milliseconds;
5656
#if SIZEOF_LONG == 4
5757
char *s_milliseconds;
58-
int s_milliseconds_len;
58+
int s_milliseconds_len;
5959
#endif
6060

6161

src/bson.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@
4141
#include "php_phongo.h"
4242
#include "php_bson.h"
4343

44-
45-
#define BSON_APPEND_INT32(b,key,val) \
46-
bson_append_int32 (b, key, (int) strlen (key), val)
47-
48-
#if SIZEOF_LONG == 8
49-
# define BSON_APPEND_INT(b, key, keylen, val) \
50-
if (val > INT_MAX || val < INT_MIN) { \
51-
bson_append_int64(b, key, keylen, val); \
52-
} else { \
53-
bson_append_int32(b, key, keylen, val); \
54-
}
55-
#elif SIZEOF_LONG == 4
56-
# define BSON_APPEND_INT(b, key, keylen, val) \
57-
bson_append_int32(b, key, keylen, val);
58-
#endif
59-
6044
#undef MONGOC_LOG_DOMAIN
6145
#define MONGOC_LOG_DOMAIN "PHONGO-BSON"
6246

@@ -1005,7 +989,17 @@ static void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, cons
1005989
#endif
1006990

1007991
case IS_LONG:
1008-
BSON_APPEND_INT(bson, key, key_len, Z_LVAL_P(entry));
992+
#if SIZEOF_LONG == 8 || (PHP_VERSION_ID >= 70000 && SIZEOF_ZEND_LONG == 8)
993+
if (val > INT_MAX || val < INT_MIN) {
994+
bson_append_int64(bson, key, keylen, Z_LVAL_P(entry));
995+
} else {
996+
bson_append_int32(bson, key, keylen, Z_LVAL_P(entry));
997+
}
998+
#elif SIZEOF_LONG == 4 || (PHP_VERSION_ID >= 70000 && SIZEOF_ZEND_LONG == 4)
999+
bson_append_int32(bson, key, keylen, Z_LVAL_P(entry));
1000+
#else
1001+
#error Need fix for this architecture
1002+
#endif
10091003
break;
10101004

10111005
case IS_DOUBLE:

tests/standalone/bug0544.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
PHPC-544: Unexpected 64-bit integer truncation
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE)?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$manager = new MongoDB\Driver\Manager(STANDALONE);
10+
11+
$bulk = new MongoDB\Driver\BulkWrite;
12+
$bulk->insert(['x' => 4294967295]);
13+
$result = $manager->executeBulkWrite(NS, $bulk);
14+
printf("Inserted %d document(s)\n", $result->getInsertedCount());
15+
16+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([]));
17+
var_dump($cursor->toArray());
18+
19+
?>
20+
===DONE===
21+
<?php exit(0); ?>
22+
--EXPECTF--
23+
Inserted 1 document(s)
24+
array(1) {
25+
[0]=>
26+
object(stdClass)#%d (%d) {
27+
["_id"]=>
28+
object(MongoDB\BSON\ObjectID)#%d (%d) {
29+
["oid"]=>
30+
string(24) "%x"
31+
}
32+
["x"]=>
33+
int(4294967295)
34+
}
35+
}
36+
===DONE===

0 commit comments

Comments
 (0)