fix(logging): make Tail/Page allocation bound explicit for CodeQL

CodeQL's Go analyzer (go/uncontrolled-allocation-size, alert #6) can't
trace min(limit, MaxTailLines) as a bound on the request-derived limit
before make([]Entry, 0, limit). The clamp was already correct and has
been in place since 5e24072 -- confirmed by rescanning at current HEAD,
the alert still fires -- so this is an analyzer gap, not a live bug.
Same clamp, written as an explicit if so static analysis (and readers)
can verify the bound directly.
This commit is contained in:
sam committed 2026-09-02 00:04:06 +10:00
1 parent 3079f86381
commit e527f0108a
1 file changed
+6 -2
+6 -2
View File
@@ -289,7 +289,9 @@ func Tail(path string, q Query) (Result, error) {
if limit <= 0 {
limit = DefaultTailLines
}
limit = min(limit, MaxTailLines)
if limit > MaxTailLines {
limit = MaxTailLines
}
matches := make([]Entry, 0, limit)
truncated, _, ok, err := readLines(path, q, 0, func(e Entry, _ int64) bool {
@@ -343,7 +345,9 @@ func Page(path string, q Query, cursor int64) (PageResult, error) {
if limit <= 0 {
limit = DefaultTailLines
}
limit = min(limit, MaxTailLines)
if limit > MaxTailLines {
limit = MaxTailLines
}
type lineAt struct {
entry Entry