@@ -638,30 +638,33 @@ bson_parser_parse (bson_parser_t *parser, bson_t *in, bson_error_t *error)
638
638
bson_iter_t iter ;
639
639
bson_parser_entry_t * entry = NULL ;
640
640
641
- BSON_FOREACH (in , iter )
642
- {
643
- const char * key = bson_iter_key (& iter );
644
- bson_parser_entry_t * matched = NULL ;
645
- /* Check for a corresponding entry. */
646
- LL_FOREACH (parser -> entries , entry )
641
+ /* Check that document is not null. */
642
+ if (in ) {
643
+ BSON_FOREACH (in , iter )
647
644
{
648
- if (0 == strcmp (entry -> key , key )) {
649
- matched = entry ;
650
- break ;
645
+ const char * key = bson_iter_key (& iter );
646
+ bson_parser_entry_t * matched = NULL ;
647
+ /* Check for a corresponding entry. */
648
+ LL_FOREACH (parser -> entries , entry )
649
+ {
650
+ if (0 == strcmp (entry -> key , key )) {
651
+ matched = entry ;
652
+ break ;
653
+ }
651
654
}
652
- }
653
655
654
- if (matched ) {
655
- if (!entry_marshal (entry , & iter , error )) {
656
+ if (matched ) {
657
+ if (!entry_marshal (entry , & iter , error )) {
658
+ return false;
659
+ }
660
+ entry -> set = true;
661
+ } else if (parser -> allow_extra ) {
662
+ BSON_APPEND_VALUE (parser -> extra , key , bson_iter_value (& iter ));
663
+ } else {
664
+ test_set_error (
665
+ error , "Extra field '%s' found parsing: %s" , key , tmp_json (in ));
656
666
return false;
657
667
}
658
- entry -> set = true;
659
- } else if (parser -> allow_extra ) {
660
- BSON_APPEND_VALUE (parser -> extra , key , bson_iter_value (& iter ));
661
- } else {
662
- test_set_error (
663
- error , "Extra field '%s' found parsing: %s" , key , tmp_json (in ));
664
- return false;
665
668
}
666
669
}
667
670
0 commit comments