{"action":"reopened","issue":{"url":"https://api.github.com/repos/golang/go/issues/14377","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/14377/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/14377/comments","events_url":"https://api.github.com/repos/golang/go/issues/14377/events","html_url":"https://github.com/golang/go/issues/14377","id":134473578,"number":14377,"title":"sort: go 1.6 panic: runtime error: index out of range","user":{"login":"stevenh","id":104239,"avatar_url":"https://avatars.githubusercontent.com/u/104239?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenh","html_url":"https://github.com/stevenh","followers_url":"https://api.github.com/users/stevenh/followers","following_url":"https://api.github.com/users/stevenh/following{/other_user}","gists_url":"https://api.github.com/users/stevenh/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenh/subscriptions","organizations_url":"https://api.github.com/users/stevenh/orgs","repos_url":"https://api.github.com/users/stevenh/repos","events_url":"https://api.github.com/users/stevenh/events{/privacy}","received_events_url":"https://api.github.com/users/stevenh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/36","html_url":"https://github.com/golang/go/milestones/Go1.6.1","labels_url":"https://api.github.com/repos/golang/go/milestones/36/labels","id":1589951,"number":36,"title":"Go1.6.1","description":"","creator":{"login":"ianlancetaylor","id":3194333,"avatar_url":"https://avatars.githubusercontent.com/u/3194333?v=3","gravatar_id":"","url":"https://api.github.com/users/ianlancetaylor","html_url":"https://github.com/ianlancetaylor","followers_url":"https://api.github.com/users/ianlancetaylor/followers","following_url":"https://api.github.com/users/ianlancetaylor/following{/other_user}","gists_url":"https://api.github.com/users/ianlancetaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/ianlancetaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianlancetaylor/subscriptions","organizations_url":"https://api.github.com/users/ianlancetaylor/orgs","repos_url":"https://api.github.com/users/ianlancetaylor/repos","events_url":"https://api.github.com/users/ianlancetaylor/events{/privacy}","received_events_url":"https://api.github.com/users/ianlancetaylor/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":0,"state":"open","created_at":"2016-02-18T03:45:44Z","updated_at":"2016-02-18T13:24:17Z","due_on":"2016-03-17T07:00:00Z","closed_at":null},"comments":8,"created_at":"2016-02-18T03:44:13Z","updated_at":"2016-02-18T13:24:17Z","closed_at":null,"body":"It looks like the recent sort improvements, released in go 1.6 result in a runtime panic: index out of range\r\n\r\nAfter updating to go 1.6 a simple sort that was working fine in 1.5.3 now causes a panic: runtime error: index out of range.\r\n\r\nI added some debugging to try can catch it in the act and it seems like go 1.6's sort may be broken.\r\n\r\nOutput:\r\n```\r\nLEN: 189\r\nLEN: 189 i: 95 j: 189\r\npanic: runtime error: index out of range\r\n```\r\n\r\nI should never see that second LEN call as it means that sort called Less with i or j >= Len().\r\n\r\nCode snippet\r\n```go\r\nfunc (ba Sorter) Len() int {\r\n        fmt.Println(\"LEN:\", len(ba))\r\n        return len(ba)\r\n}\r\n\r\nfunc (ba Sorter) Less(i, j int) bool {\r\n        if len(ba) <= i || len(ba) <= j {\r\n                fmt.Println(\"LEN:\", len(ba), \"i:\", i, \"j:\", j)\r\n        }\r\n        a, b := ba[i], ba[j] // <-- Panic happens here\r\n...\r\n}\r\n\r\nfunc (ba Sorter) Swap(i, j int) {\r\n        ba[i], ba[j] = ba[j], ba[i]\r\n} \r\n```\r\n\r\nReverting: https://github.com/golang/go/commit/e71d64012c9d9dc744bc9a780b4afccd8f5b029d makes the problem go away.\r\n\r\n```\r\npanic: runtime error: index out of range\r\n\r\ngoroutine 23 [running]:\r\npanic(0x8a4440, 0xc82000e100)\r\n        /usr/local/go/src/runtime/panic.go:464 +0x3e6\r\nSorter.Less(0xc82018a000, 0xd6, 0x3e8, 0x1d, 0xffffffffffffffff, 0x1)\r\n        sort.go:19 +0x41f\r\n(*Sorter).Less(0xc820fc83c0, 0x1d, 0xffffffffffffffff, 0x1)\r\n        <autogenerated>:471 +0xb5\r\nsort.doPivot(0x800d81000, 0xc820fc83c0, 0x1d, 0x35, 0x1a, 0x3d)\r\n        /usr/local/go/src/sort/sort.go:128 +0x27b\r\nsort.quickSort(0x800d81000, 0xc820fc83c0, 0x1d, 0x35, 0xc)\r\n        /usr/local/go/src/sort/sort.go:195 +0xa3\r\nsort.quickSort(0x800d81000, 0xc820fc83c0, 0x0, 0x35, 0xd)\r\n        /usr/local/go/src/sort/sort.go:202 +0x12a\r\nsort.quickSort(0x800d81000, 0xc820fc83c0, 0x0, 0xd6, 0xf)\r\n        /usr/local/go/src/sort/sort.go:199 +0xfe\r\nsort.Sort(0x800d81000, 0xc820fc83c0)\r\n        /usr/local/go/src/sort/sort.go:229 +0x74\r\n```"}}