diff --git a/src/bson_object.c b/src/bson_object.c index b517789..2bc6d27 100644 --- a/src/bson_object.c +++ b/src/bson_object.c @@ -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; } \ No newline at end of file diff --git a/src/bson_object.h b/src/bson_object.h index 7717931..847abc8 100644 --- a/src/bson_object.h +++ b/src/bson_object.h @@ -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);