fix: staticcheck and deadcode findings repo-wide, modernize counting loops

This commit is contained in:
2026-08-29 15:25:15 +02:00
parent 9a34733615
commit eacf33d0f7
33 changed files with 88 additions and 250 deletions
+3 -11
View File
@@ -66,7 +66,7 @@ mnemonic, so the audit tracks whatever toolchain `+"`go env GOROOT`"+` names.
return err
}
var superset, backlog, shared, goOnly []string
var superset, backlog, shared []string
for _, name := range names {
switch {
case !asm.Encodable(name):
@@ -77,16 +77,8 @@ mnemonic, so the audit tracks whatever toolchain `+"`go env GOROOT`"+` names.
shared = append(shared, name)
}
}
for _, name := range names {
if goKnown[name] && !seen[name] {
goOnly = append(goOnly, name)
}
}
// GO-ONLY is computed from the complement of the gasm table, which this
// audit cannot enumerate (Go's table is only visible through probes of
// names we already know). Report it as informational zero instead of a
// misleading list.
goOnly = nil
// GO-ONLY is not enumerable by probing: Go's table is only visible
// through names we already know, so nothing can be reported there.
sort.Strings(superset)
sort.Strings(backlog)
+2 -2
View File
@@ -1526,7 +1526,7 @@ func cmdVerifyCall(k *verify.Kernel, path, funcName, bufSpec, scalarSpec string,
fmt.Printf(" args before: %s\n", hexDump(args))
rc := 0
for i := 0; i < repeat; i++ {
for i := range repeat {
out, err := k.CallFunc(funcName, args)
if err != nil {
fmt.Printf(" call %d: FAIL — %v\n", i+1, err)
@@ -1575,7 +1575,7 @@ func hexDump(buf []byte) string {
n = max
}
var sb strings.Builder
for i := 0; i < n; i++ {
for i := range n {
if i > 0 {
sb.WriteByte(' ')
}
+16 -5
View File
@@ -60,6 +60,7 @@ bodies, place the file in the kernel's package, and run it in CI.
out.WriteString(headerComment)
out.WriteString("package " + packageName + "\n\n")
out.WriteString("import (\n\t\"bytes\"\n\t\"math/rand\"\n\t\"testing\"\n)\n\n")
out.WriteString(generatedHelpers)
kernels := 0
for _, d := range f.Decls {
@@ -305,9 +306,12 @@ func goCast(elem string) string {
}
}
// outputBytes narrows a returned slice to bytes for the comparison; scalar
// results are compared through the same helper via a reflect-free trick the
// author may need to adjust for non-slice returns.
// generatedHelpers is emitted into every generated test file: outputBytes
// narrows returned slices and scalars to a byte form for the comparison.
// It lives in the template, not in this binary, because only the generated
// file ever calls it.
const generatedHelpers = `// outputBytes narrows a returned slice or scalar to bytes for the
// comparison; extend the switch when a kernel returns a wider type.
func outputBytes(v any) []byte {
switch t := v.(type) {
case []byte:
@@ -324,11 +328,18 @@ func outputBytes(v any) []byte {
case []uint16:
b := make([]byte, 2*len(t))
for i, x := range t {
b[i*4/2] = byte(x)
b[i*4/2+1] = byte(x >> 8)
b[i*2] = byte(x)
b[i*2+1] = byte(x >> 8)
}
return b
case int:
b := make([]byte, 8)
for i := 0; i < 8; i++ {
b[i] = byte(uint64(t) >> (8 * i))
}
return b
default:
return nil
}
}
`