simple prove code:
const char * sd = "{\"v\":-1234567890123, \"x\":12345678901234}"; bson_error_t err; bson_t * bs = bson_new_from_json((const uint8_t*)sd, strlen(sd), &err); printf("%s\n", bson_as_json(bs, 0));
the code will got:
{ "v" : -1912276171, "x" : 12345678901234 }
-1234567890123 losts its width, narow down to int32.
The bug is caused by src/bson/bson-json.c:431:
if (val <= INT32_MAX) { bson_append_int32 (STACK_BSON_CHILD, key, (int)len, (int)val); } else { bson_append_int64 (STACK_BSON_CHILD, key, (int)len, val); }
change
if (val<=INT32_MAX)
to
if (val<=INT32_MAX && val>=INT32_MIN)
can fix this bug.