This commit is contained in:
2026-06-20 19:16:44 +08:00
parent db3d030169
commit dbb87823e8
26 changed files with 676 additions and 115 deletions
+4 -1
View File
@@ -68,7 +68,10 @@ func sliceLines(s string, line, limit *int) string {
}
end := len(lines)
if limit != nil && *limit >= 0 {
if start+*limit < end {
// overflow-safe:用剩余行数为上限做钳制,避免 start+*limit 在 *limit 很大
// (如 math.MaxInt)时整数溢出为负,绕过下界判断后导致 lines[start:end] panic。
remaining := len(lines) - start
if *limit < remaining {
end = start + *limit
}
}