Skip to content

Commit a222e39

Browse files
committed
Convert overflown int64 to strings and print a warning
1 parent 8158760 commit a222e39

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/bson.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,13 @@ bool php_phongo_bson_visit_int64(const bson_iter_t *iter ARG_UNUSED, const char
382382
zval *retval = ((php_phongo_bson_state *)data)->zchild;
383383

384384
#if SIZEOF_LONG == 4
385-
if (v_int64 > INT_MAX) {
386-
mongoc_log(MONGOC_LOG_LEVEL_ERROR, MONGOC_LOG_DOMAIN, "Integer overflow detected on your platform: %lld", v_int64);
385+
if (v_int64 > LONG_MAX || v_int64 < LONG_MIN) {
386+
char *tmp;
387+
int tmp_len;
388+
389+
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Integer overflow detected on your platform: %lld", v_int64);
390+
tmp_len = spprintf(&tmp, 0, "%lld", v_int64);
391+
add_assoc_stringl(retval, key, tmp, tmp_len, 0);
387392
return false;
388393
}
389394
#endif

0 commit comments

Comments
 (0)