Skip to content

Commit

Permalink
Merge pull request #20 from TimMensch/justfix2
Browse files Browse the repository at this point in the history
Fix BSON parsing to treat numbers larger than INT_MAX as doubles
  • Loading branch information
pakozm committed May 6, 2014
2 parents db2547f + 5b09eb7 commit cd40440
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {

#include "utils.h"
#include "common.h"
#include <limits.h>

using namespace mongo;

Expand Down Expand Up @@ -246,7 +247,7 @@ static void lua_append_bson(lua_State *L, const char *key, int stackpos, BSONObj
builder->appendNull(key);
} else if (type == LUA_TNUMBER) {
double numval = lua_tonumber(L, stackpos);
if (numval == floor(numval)) {
if ((numval == floor(numval)) && fabs(numval)< INT_MAX ) {
// The numeric value looks like an integer, treat it as such.
// This is closer to how JSON datatypes behave.
int intval = lua_tointeger(L, stackpos);
Expand Down

0 comments on commit cd40440

Please sign in to comment.