From ca71c0300f4a10386dc3af6445c420775f89ee0f Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 9 Jan 2016 01:23:38 +0100 Subject: [PATCH] avoid infinite loop in next uuid generation --- common/uuid/uuid.go | 1 + common/uuid/uuid_test.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/common/uuid/uuid.go b/common/uuid/uuid.go index 56a7f9fc..1a1ed072 100644 --- a/common/uuid/uuid.go +++ b/common/uuid/uuid.go @@ -47,6 +47,7 @@ func (this *UUID) Next() *UUID { if !newid.Equals(this) { return newid } + md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2")) } } diff --git a/common/uuid/uuid_test.go b/common/uuid/uuid_test.go index 04bd9f6f..dac56d6b 100644 --- a/common/uuid/uuid_test.go +++ b/common/uuid/uuid_test.go @@ -50,3 +50,12 @@ func TestRandom(t *testing.T) { assert.StringLiteral(uuid.String()).NotEquals(uuid2.String()) assert.Bytes(uuid.Bytes()).NotEquals(uuid2.Bytes()) } + +func TestEquals(t *testing.T) { + v2testing.Current(t) + + var uuid *UUID = nil + var uuid2 *UUID = nil + assert.Bool(uuid.Equals(uuid2)).IsTrue() + assert.Bool(uuid.Equals(New())).IsFalse() +}