Skip to content

Commit d4bb201

Browse files
committed
out of range fix
1 parent dd5e4c1 commit d4bb201

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

datautil/datautil.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ func FindValidPart(data []byte) (int, int) {
5454
return 0, 0
5555
}
5656

57+
a := (n - r) % 20
58+
if a == 0 {
59+
a = 20
60+
}
61+
5762
// 也许收获满满
58-
r = n - (n-r)%20
63+
r = n - a
5964
return l, r + 1
6065
}
6166

datautil/datautil_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,60 @@ func TestFindValidPart(t *testing.T) {
115115
startIdx: 5,
116116
endIdx: 25,
117117
},
118+
{
119+
data: []byte{
120+
0xa,
121+
122+
0x1, 0x2, 0x4,
123+
0x30, 0x4, 0x0, 0x20,
124+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
125+
0x41, 0xe2, 0x0, 0x0,
126+
0xa,
127+
128+
0x1, 0x2, 0x4,
129+
0xa8, 0x4, 0x0, 0x20,
130+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
131+
0x41, 0xe2, 0x0, 0x0,
132+
0xa,
133+
134+
0x1, 0x2, 0x4,
135+
0xac, 0x1, 0x0, 0x20,
136+
0x0, 0x0, 0xb4, 0xbe, 0x0, 0x0, 0x0, 0x0,
137+
0x4b, 0xe2, 0x0, 0x0,
138+
0xa,
139+
140+
0x1, 0x2, 0x4,
141+
0x40, 0x3, 0x0, 0x20,
142+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
143+
0x4b, 0xe2, 0x0, 0x0,
144+
0xa,
145+
146+
0x1, 0x2, 0x4,
147+
0xb8, 0x3, 0x0, 0x20,
148+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
149+
0x4b, 0xe2, 0x0, 0x0,
150+
0xa,
151+
152+
0x1, 0x2, 0x4,
153+
0x30, 0x4, 0x0, 0x20,
154+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
155+
0x4b, 0xe2, 0x0, 0x0,
156+
0xa,
157+
158+
0x1, 0x2, 0x4,
159+
0xa8, 0x4, 0x0, 0x20,
160+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
161+
0x4b, 0xe2, 0x0, 0x0,
162+
0xa,
163+
164+
0x1, 0x2, 0x4,
165+
0xac, 0x1, 0x0, 0x20, 0x0, 0x80, 0x9d, 0xbe,
166+
0x0, 0x0, 0x0, 0x0,
167+
0x55, 0xe2, 0x0, 0x0,
168+
},
169+
startIdx: 1,
170+
endIdx: 141,
171+
},
118172
}
119173
for _, c := range cases {
120174
s, n := FindValidPart(c.data)

0 commit comments

Comments
 (0)