When called with an empty string, bson_init_from_json() and bson_new_from_json() do not set error leaving it uninitialized which produces inconsistency with the documentation and requires an extra check to be made on the calling side.
Please refer to the following code snippet:
#include <stdio.h> #include <bson.h> int main() { bson_t bson; bson_error_t error; if (!bson_init_from_json(&bson, "", -1, &error)) { printf("bson_init_from_json() failed: %s\n", error.message); return 1; } bson_destroy(&bson); return 0; }
$ ./a.out bson_init_from_json() failed: �-T��