From 0a336e4abdd7c949c9dd38037165e6a16c7d7ebf Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 24 Apr 2015 09:35:58 +0200 Subject: handles: start slot indices with 1 Using 0 as the first slot indice leads to not being able to differentiate between a handle to the first element or a NULL-handle. As current code may check whether the pointer is NULL, change the first indice to be 1 instead. --- handles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handles.go b/handles.go index a862746..d173785 100644 --- a/handles.go +++ b/handles.go @@ -23,7 +23,7 @@ func NewHandleList() *HandleList { // findUnusedSlot finds the smallest-index empty space in our // list. You must only run this function while holding a write lock. func (v *HandleList) findUnusedSlot() uintptr { - for i := 0; i < len(v.handles); i++ { + for i := 1; i < len(v.handles); i++ { isUsed := v.set[uintptr(i)] if !isUsed { return uintptr(i) -- cgit v1.2.3