Skip to content

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Dec 7, 2020

PHPC-1713

Fixes #1183.


if (data) {
ZVAL_COPY_DEREF(return_value, data);
if (Z_ISUNDEF_P(data)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance, I wondered if it would be possible for this function to still leave return_value unset.

php_phongo_cursor_get_current_data always returns a non-null pointer to a block of memory within intern, which itself is never null (we'd hit a segfault if so). In that case, I think can should drop the outer if (data) for readability -- optionally leave a comment that "data points to some memory within intern and is always non-null".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the check 👍

@@ -0,0 +1,24 @@
--TEST--
MongoDB\Driver\Cursor PHPC-171: The cursor current method does not return anything
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, the JIRA ticket is used as the test name prefix. Non-ticket tests start with a class/method name. I'd suggest:

PHPC-1713: MongoDB\Driver\Cursor::current() does not return anything

--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_live(); ?>
<?php skip_if_not_clean(); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, I don't think this matters since we don't actually care if the collection is dropped. Whether it exists or not, we're just testing that php_phongo_cursor_t.visitor_data.zchild is zeroed out before the first call to rewind() or next().

That said, no objections to keeping this in place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I've dropped the call, no reason to clear the database if we don't care about its contents.

@alcaeus alcaeus requested a review from jmikola December 21, 2020 15:39
@alcaeus
Copy link
Member Author

alcaeus commented Dec 21, 2020

@jmikola realised I (once again) targeted the wrong branch with the PR. Will rebase onto v1.9 and merge after that.

@jmikola jmikola changed the title [PHPC-1713] Ensure Cursor::current returns null on invalid positions PHPC-1713: Ensure Cursor::current returns null on invalid positions Dec 22, 2020
@alcaeus alcaeus changed the base branch from master to v1.9 December 22, 2020 13:36
@alcaeus alcaeus merged commit 70a097e into mongodb:v1.9 Dec 22, 2020
@alcaeus alcaeus deleted the phpc-1713 branch December 22, 2020 13:37
alcaeus added a commit that referenced this pull request Jan 13, 2021
* v1.9:
  PHPC-1713: Ensure Cursor::current returns null on invalid positions (#1186)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cursor] the current method does not return anything!

2 participants