Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sortedlist): 修复 All() 方法中因 nil 值导致的 panic 问题 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bistutu
Copy link

@Bistutu Bistutu commented Oct 20, 2024

修复内容

sortedlist 包的 appendValue 函数中,修正了 All 方法初始化迭代器时将 nil 作为第一个元素添加到数据切片中,导致后续类型断言 iter.Value().(Segment) 时发生 panic 的问题。bug 来源于相关issue:#3

具体修改

将原先的条件判断:

if t.key >= lower && t.key <= upper {
    values = append(values, t.value)
}

修改为:

if t.key >= lower && t.key <= upper && t.value != nil {
    values = append(values, t.value)
}

确保只有非 nil 的值才会被添加到迭代器的数据切片中,从而避免类型断言时的 panic。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant