Skip to content

Commit 3b48beb

Browse files
committed
bson bugfix
1 parent 4cbead2 commit 3b48beb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lualib-src/lua-bson.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,16 @@ append_key(struct bson *bs, int type, const char *key, size_t sz) {
243243
write_string(bs, key, sz);
244244
}
245245

246+
static inline int
247+
is_32bit(int64_t v) {
248+
return v >= INT32_MIN && v <= INT32_MAX;
249+
}
250+
246251
static void
247252
append_number(struct bson *bs, lua_State *L, const char *key, size_t sz) {
248253
if (lua_isinteger(L, -1)) {
249254
int64_t i = lua_tointeger(L, -1);
250-
int si = i >> 31;
251-
if (si == 0 || si == -1) {
255+
if (is_32bit(i)) {
252256
append_key(bs, BSON_INT32, key, sz);
253257
write_int32(bs, i);
254258
} else {

0 commit comments

Comments
 (0)