Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
routing: fix slice mutation bug that could result in an infinite loop
This commit fixes a pretty nasty unnoticed bug within the main k-shortest paths algorithm loop. After a new candidate path is found, the rootPath (the path up to the pivot node) and the spurPath (the _new_ path after the pivot node) are to be combined into a new candiate shortest path. The prior logic simply appended the spurPath onto the end of the rootPath to create a slice. However, if the case that the currnet rootPath is really a sub-path in a larger slice, then this will mutate the underlying slice. This bug would manifest when doing path finding and cause an infinite loop as the slice kept growing with new spurPaths, causing the loop to never terminate. We remedy this bug by properly create a new backing slice, and adding the elements to them rather than incorrectly mutating an underlying slice.
- Loading branch information