Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Queue.deQueue() #47

Closed
JenkinsJB opened this issue Jul 27, 2015 · 3 comments
Closed

Bug in Queue.deQueue() #47

JenkinsJB opened this issue Jul 27, 2015 · 3 comments

Comments

@JenkinsJB
Copy link

I think there is a bug in the implementation of Queue.deQueue() . Consider the following code:

var w = Queue<Int>()
println(w.count) // prints "0" as expected
w.enQueue(1)
println(w.count) // prints "1" - as expected
w.deQueue()
println(w.count) // should print "0", but instead, you get a fatal error

In xCode 6.3.1, this code in a playground gives the following fatal error: fatal error: unexpectedly found nil while unwrapping an Optional value Playground execution failed: Execution was interrupted, reason: EXC_BAD_INSTRUCTION

This is due to the fact that deQueue() at line 102 sets top to nil when there is no next item in the queue. count then blows up when it tries to access top.key which is an implicitly unwrapped optional. A fix would be to instead set top to QNode<T>() on 102.

@JenkinsJB
Copy link
Author

Pull request with fix created.

Jason

@JenkinsJB
Copy link
Author

Created new PR against develop branch per tweet from @waynewbishop

@waynewbishop
Copy link
Owner

Hi Jason;

Thanks again for fixing this issue. Your changes have been merged into the main branch along with some new unit tests!

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 a pull request may close this issue.

2 participants