Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-22 09:54:24 +01:00

Fix missing error check of bufio.Scanner (#29882)

maybe more

(cherry picked from commit 0e183d81fc5283f9d2047472de580e4f04a046c1)
This commit is contained in:
coldWater 2024-03-19 10:20:36 +08:00 committed by Earl Warren
parent 40c9fa43cd
commit 664052fb0b
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
7 changed files with 30 additions and 0 deletions

View file

@ -211,6 +211,10 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
return err
}
}
err = scanner.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
}
f.Close()
}
return nil

View file

@ -133,6 +133,10 @@ func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
return err
}
}
err = scanner.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
}
f.Close()
}
return nil

View file

@ -9,6 +9,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os/exec"
"strconv"
@ -390,6 +391,10 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
}
}
}
err = scanner.Err()
if err != nil {
return nil, fmt.Errorf("scan: %w", err)
}
return c.submoduleCache, nil
}

View file

@ -124,6 +124,10 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
}
}
}
err = scanner.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
}
a := make([]*CodeActivityAuthor, 0, len(authors))
for _, v := range authors {
a = append(a, v)

View file

@ -6,6 +6,7 @@ package markup
import (
"bufio"
"bytes"
"fmt"
"html"
"io"
"regexp"
@ -123,6 +124,10 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
return err
}
}
err = scan.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
}
_, err = tmpBlock.WriteString("</pre>")
if err != nil {

View file

@ -980,5 +980,9 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
}
diffLines = append(diffLines, diffLine)
}
err = scanner.Err()
if err != nil {
return nil, fmt.Errorf("scan: %w", err)
}
return diffLines, nil
}

View file

@ -50,6 +50,10 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
}
linesInAuthorizedKeys.Add(line)
}
err = scanner.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
}
f.Close()
// now we regenerate and check if there are any lines missing