Skip to content

Commit

Permalink
Fixes segfault in bson_object_iterator_next
Browse files Browse the repository at this point in the history
Updating description according to new behavior.
  • Loading branch information
jacobkeeler committed Oct 30, 2017
1 parent a3a1dc6 commit dee59a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/bson_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,13 @@ MapIterator bson_object_iterator(BsonObject *obj) {
BsonObjectEntry bson_object_iterator_next(MapIterator *iterator) {
MapEntry *entry = emhashmap_iterator_next(iterator);
BsonObjectEntry bsonEntry;
strncpy(bsonEntry.key, entry->key, 255);
bsonEntry.element = (BsonElement *)entry->value;
if(entry == NULL) {
bsonEntry.key[0] = 0x00; //Assign empty string
bsonEntry.element = NULL;
}
else {
strncpy(bsonEntry.key, entry->key, 255);
bsonEntry.element = (BsonElement *)entry->value;
}
return bsonEntry;
}
3 changes: 2 additions & 1 deletion src/bson_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ MapIterator bson_object_iterator(BsonObject *obj);
@param iterator - The iterator to be advanced
@return - The next BSON object entry in the object if it exists,
NULL if the iterator has moved past the end of the entry list
an entry with a NULL element if the iterator has moved past the end
of the entry list
*/
BsonObjectEntry bson_object_iterator_next(MapIterator *iterator);

Expand Down

0 comments on commit dee59a3

Please sign in to comment.