From 57bbf326a7e7368fb310dfe3f1f4f7128ce4714b Mon Sep 17 00:00:00 2001 From: XinRoom <32238570+XinRoom@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:42:57 +0800 Subject: [PATCH] fix: NarrowMode rangeSpace uint8 overflow eg: 1.1.1.0-255 --- iterator.go | 4 ++-- iterator_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iterator.go b/iterator.go index e413802..2e1e564 100644 --- a/iterator.go +++ b/iterator.go @@ -317,10 +317,10 @@ func (it *Iter) incByIndex(index uint64) { } else { length := len(it.classmate) ip := make([]byte, length) - rangeSpace := make([]uint8, length) + rangeSpace := make([]uint, length) // 每一位的空间容量 for i, rangeMate := range it.classmate { - rangeSpace[i] = rangeMate.e - rangeMate.s + 1 + rangeSpace[i] = uint(rangeMate.e-rangeMate.s) + 1 } // transform 进位除余 carryBit := uint64(0) // 进位 diff --git a/iterator_test.go b/iterator_test.go index 9327bbb..57eb080 100644 --- a/iterator_test.go +++ b/iterator_test.go @@ -6,7 +6,7 @@ import ( ) func TestName(t *testing.T) { - for _, v := range []string{"1.1.1.1", "1.1.1.2/30", "1.1.1.1-3", "1.1-2.0-1.4", "1.1.1.1-1.1.2.1", "2001::59:63", "2001::59:63/126", "2001::59:63-f2", "2001::59-60:63-f2", "2001::59:63-2001::59:f2"} { + for _, v := range []string{"1.1.1.1", "1.1.1.2/30", "1.1.1.0-255", "1.1-2.0-1.4", "1.1.1.1-1.1.2.1", "2001::59:63", "2001::59:63/126", "2001::59:63-f2", "2001::59-60:63-f2", "2001::59:63-2001::59:f2"} { t.Logf("Test %s", v) it, startIp, err := NewIter(v) if err != nil {