Skip to content

Commit

Permalink
fix: 修复潜在数组越界的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlleo committed May 27, 2022
1 parent 84c48da commit 9656dfe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,24 @@ func (r *reporter) InitialBaseData() Reporter {
func (r *reporter) Print() {
var beforeActiveTTL uint16 = 0
r.InitialBaseData()
for i := uint16(1); i < r.targetTTL; i++ {
// 尝试首个有效 TTL
for i := uint16(0); i < r.targetTTL; i++ {
if len(r.routeReport[i]) != 0 {
beforeActiveTTL = i
// 找到以后便不再循环
break
}
}

for i := beforeActiveTTL; i < r.targetTTL; i++ {
// 计算该TTL内的数据长度,如果为0,则代表没有有效数据
if len(r.routeReport[i]) == 0 {
// 跳过改跃点的数据整理
continue
}
nodeReport := r.routeReport[i][0]

if i == 1 {
if i == beforeActiveTTL {
fmt.Printf("AS%s %s「%s『%s", nodeReport.asn, nodeReport.isp, nodeReport.geo[0], nodeReport.geo[1])
} else {
nodeReportBefore := r.routeReport[beforeActiveTTL][0]
Expand Down

0 comments on commit 9656dfe

Please sign in to comment.