Skip to content
This repository

Fix BSON parsing to treat numbers larger than INT_MAX as doubles #20

Merged
merged 1 commit into from 2 months ago

2 participants

Tim Mensch Francisco Zamora-Martinez
Tim Mensch

Hi,

I had a case where ended up pushing large numbers into MongoDB, and they ended up squeezed into an int32_t. This patch adds a simple "If < INT_MAX" at the point where it decides to use an int or a double.

Tim

Francisco Zamora-Martinez pakozm merged commit cd40440 into from
Francisco Zamora-Martinez pakozm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 25, 2012
Tim Mensch Fix BSON parsing to treat numbers larger than INT_MAX as doubles 5b09eb7
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  utils.cpp
3  utils.cpp
@@ -13,6 +13,7 @@ extern "C" {
13 13
14 14 #include "utils.h"
15 15 #include "common.h"
  16 +#include <limits.h>
16 17
17 18 using namespace mongo;
18 19
@@ -246,7 +247,7 @@ static void lua_append_bson(lua_State *L, const char *key, int stackpos, BSONObj
246 247 builder->appendNull(key);
247 248 } else if (type == LUA_TNUMBER) {
248 249 double numval = lua_tonumber(L, stackpos);
249   - if (numval == floor(numval)) {
  250 + if ((numval == floor(numval)) && fabs(numval)< INT_MAX ) {
250 251 // The numeric value looks like an integer, treat it as such.
251 252 // This is closer to how JSON datatypes behave.
252 253 int intval = lua_tointeger(L, stackpos);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.