This repository was archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
\Zend\Stdlib\FastPriorityQueue - an infinite loop and bugs in remove() #60
Merged
weierophinney
merged 7 commits into
zendframework:master
from
piowin:fix/infinite-loop-and-remove-method
Apr 12, 2018
Merged
\Zend\Stdlib\FastPriorityQueue - an infinite loop and bugs in remove() #60
weierophinney
merged 7 commits into
zendframework:master
from
piowin:fix/infinite-loop-and-remove-method
Apr 12, 2018
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Inserting elements at 0 priority causes an infinite loop. For example, when we run the following snippet of code, we fall into an infinite loop: ```php $queue = new FastPriorityQueue(); $queue->insert('a', 0); $queue->insert('b', 1); foreach ($queue as $value) {echo $value;} ```
This commmit fixes the implementaion of the `\Zend\Stdlib\FastPriorityQueue::remove()` method.
Can you add tests? |
@Peterr As noted by @vaclavvanik , we need tests demonstrating the infinite loop, so we can validate the fix, but also to ensure that the issue is not re-introduced. Thanks in advance! |
Ocramius
reviewed
Sep 14, 2016
*/ | ||
protected $maxPriority = 0; | ||
protected $maxPriority = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly a BC break, since FastPriorityQueue
is not final
weierophinney
added a commit
that referenced
this pull request
Apr 12, 2018
\Zend\Stdlib\FastPriorityQueue - an infinite loop and bugs in remove()
weierophinney
added a commit
that referenced
this pull request
Apr 12, 2018
weierophinney
added a commit
that referenced
this pull request
Apr 12, 2018
Thanks, @Peterr! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I see a few problems in the class.
Other problems are concerned with the implementation of the
remove()
method.remove()
changes a value ofthis->maxPriority
:remove()
uses thenext()
method thus it changes the internal array pointer:remove()
doesn't destroy the unnecessary priority from the array of priorities which implies the following behaviour:This PR fixes all these issues.