Skip to content

Commit ad47d5c

Browse files
committed
Check the correct iterator for the 'limit' field
1 parent 7f6ae5b commit ad47d5c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/mongoc/mongoc-write-command.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ _mongoc_write_command_delete_legacy (mongoc_write_command_t *command,
591591
bson_iter_t iter;
592592
bson_iter_t q_iter;
593593
uint32_t len;
594+
int64_t limit = 0;
594595
bson_t *gle = NULL;
595596
char ns [MONGOC_NAMESPACE_MAX + 1];
596597
bool r;
@@ -645,13 +646,14 @@ _mongoc_write_command_delete_legacy (mongoc_write_command_t *command,
645646
rpc.delete_.opcode = MONGOC_OPCODE_DELETE;
646647
rpc.delete_.zero = 0;
647648
rpc.delete_.collection = ns;
648-
if (bson_iter_find (&iter, "limit") && (BSON_ITER_HOLDS_INT32 (&iter) ||
649-
BSON_ITER_HOLDS_INT64 (&iter))) {
650-
rpc.delete_.flags = bson_iter_as_int64 (&iter) ? MONGOC_DELETE_SINGLE_REMOVE
651-
: MONGOC_DELETE_NONE;
652-
} else {
653-
rpc.delete_.flags = MONGOC_DELETE_NONE;
649+
650+
if (bson_iter_find (&q_iter, "limit") &&
651+
(BSON_ITER_HOLDS_INT32 (&q_iter) || BSON_ITER_HOLDS_INT64 (&q_iter))) {
652+
limit = bson_iter_as_int64 (&q_iter);
654653
}
654+
655+
rpc.delete_.flags = limit ? MONGOC_DELETE_SINGLE_REMOVE
656+
: MONGOC_DELETE_NONE;
655657
rpc.delete_.selector = data;
656658

657659
_mongoc_monitor_legacy_write (client, command, database, collection,

0 commit comments

Comments
 (0)