Skip to content

Commit fa0b68d

Browse files
committed
Fix out-of-range error
1 parent 203b92f commit fa0b68d

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

tests/check_thread_get_posts.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -381,22 +381,24 @@ func PerfThreadGetPostsSuccess(p *Perf, f *Factory) {
381381
index = len(expected)
382382
}
383383
if rand.Int()&1 == 0 {
384-
rnd := rand.Intn(len(expected))
385-
a := limitType(expected[rnd])
386-
if reverse {
387-
for index = rnd + 1; index < len(expected); index++ {
388-
item := expected[index]
389-
if a != limitType(item) {
390-
last_id = &expected[index].ID
391-
break
384+
if len(expected) > 0 {
385+
rnd := rand.Intn(len(expected))
386+
a := limitType(expected[rnd])
387+
if reverse {
388+
for index = rnd + 1; index < len(expected); index++ {
389+
item := expected[index]
390+
if a != limitType(item) {
391+
last_id = &expected[index].ID
392+
break
393+
}
392394
}
393-
}
394-
} else {
395-
for index = rnd - 1; index >= 0; index-- {
396-
item := expected[index]
397-
if a != limitType(item) {
398-
last_id = &expected[index].ID
399-
break
395+
} else {
396+
for index = rnd - 1; index >= 0; index-- {
397+
item := expected[index]
398+
if a != limitType(item) {
399+
last_id = &expected[index].ID
400+
break
401+
}
400402
}
401403
}
402404
}

0 commit comments

Comments
 (0)