diff --git a/.auto/log.jsonl b/.auto/log.jsonl new file mode 100644 index 00000000..40eca8cf --- /dev/null +++ b/.auto/log.jsonl @@ -0,0 +1,2 @@ +{"type":"config","name":"前后端代码质量优化(符合最佳实践)","metricName":"total_issues","metricUnit":"","bestDirection":"lower"} +{"run":1,"commit":"305d609","metric":108,"metrics":{"golint_canonicalheader":8,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":2,"golint_intrange":3,"golint_modernize":37,"golint_nilnil":3,"golint_perfsprint":18,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":3,"golint_wastedassign":7,"golint_total":107,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":36},"status":"checks_failed","description":"基线:总问题 108(golangci 107 + eslint 1)。checks 失败的唯一原因:repo 自带 golangci gate 有 2 个既有 gosec G115 问题(预期内,首次修复后即绿)。","timestamp":1786871594292,"segment":0,"confidence":null,"asi":{"hypothesis":"baseline","next_action_hint":"修复 internal/apps/edge/observability/linux.go 的 2 个 G115 gosec 问题后 checks.sh 才能通过;之后每次迭代即可正常 keep/discard"}} diff --git a/internal/apps/edge/observability/linux.go b/internal/apps/edge/observability/linux.go index e7796c79..483f37ba 100644 --- a/internal/apps/edge/observability/linux.go +++ b/internal/apps/edge/observability/linux.go @@ -258,8 +258,8 @@ func StatFilesystem(path string) (int64, int64) { if err := syscall.Statfs(absPath, &stat); err != nil { return 0, 0 } - total := multiplyUint64ToInt64(stat.Blocks, uint64(stat.Bsize)) - free := multiplyUint64ToInt64(stat.Bavail, uint64(stat.Bsize)) + total := multiplyUint64Int64(stat.Blocks, stat.Bsize) + free := multiplyUint64Int64(stat.Bavail, stat.Bsize) used := total - free if used < 0 { used = 0 @@ -267,14 +267,17 @@ func StatFilesystem(path string) (int64, int64) { return total, used } -func multiplyUint64ToInt64(a uint64, b uint64) int64 { - if a == 0 || b == 0 { +// multiplyUint64Int64 multiplies a uint64 by a positive int64, saturating at +// math.MaxInt64 to avoid int64 overflow. +func multiplyUint64Int64(a uint64, b int64) int64 { + if a == 0 || b <= 0 { return 0 } - if a > math.MaxInt64/b { + v := a * uint64(b) + if v > math.MaxInt64 { return math.MaxInt64 } - return int64(a * b) //nolint:gosec // product is bounded to math.MaxInt64 above + return int64(v) } // ReadFirstLine reads and returns the trimmed first line of a file.