mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
Fix QF1012 violations and drop suppression
This commit is contained in:
@@ -239,12 +239,6 @@ analyzers:
|
||||
# See above.
|
||||
- "symbol \"runtime_pollWaitCanceled\".*"
|
||||
- "symbol \"runtime_procPin\".*"
|
||||
QF1012: # Use `fmt.Fprintf(x, ...)` instead of `x.Write(fmt.Sprintf(...))`
|
||||
# disabled for now due to existing violations.
|
||||
generated:
|
||||
exclude: [".*"]
|
||||
internal:
|
||||
exclude: [".*"]
|
||||
S1000: # Use plain channel ops instead of single-case select
|
||||
# disabled for now due to existing violations.
|
||||
internal:
|
||||
|
||||
+14
-15
@@ -54,9 +54,9 @@ func decode(inst Instruction, line int, w *bytes.Buffer) error {
|
||||
case Ldx:
|
||||
err = decodeLdx(inst, w)
|
||||
case St:
|
||||
w.WriteString(fmt.Sprintf("M[%v] <- A", inst.K))
|
||||
fmt.Fprintf(w, "M[%v] <- A", inst.K)
|
||||
case Stx:
|
||||
w.WriteString(fmt.Sprintf("M[%v] <- X", inst.K))
|
||||
fmt.Fprintf(w, "M[%v] <- X", inst.K)
|
||||
case Alu:
|
||||
err = decodeAlu(inst, w)
|
||||
case Jmp:
|
||||
@@ -77,21 +77,21 @@ func decodeLd(inst Instruction, w *bytes.Buffer) error {
|
||||
|
||||
switch inst.OpCode & loadModeMask {
|
||||
case Imm:
|
||||
w.WriteString(fmt.Sprintf("%v", inst.K))
|
||||
fmt.Fprintf(w, "%v", inst.K)
|
||||
case Abs:
|
||||
w.WriteString(fmt.Sprintf("P[%v:", inst.K))
|
||||
fmt.Fprintf(w, "P[%v:", inst.K)
|
||||
if err := decodeLdSize(inst, w); err != nil {
|
||||
return err
|
||||
}
|
||||
w.WriteString("]")
|
||||
case Ind:
|
||||
w.WriteString(fmt.Sprintf("P[X+%v:", inst.K))
|
||||
fmt.Fprintf(w, "P[X+%v:", inst.K)
|
||||
if err := decodeLdSize(inst, w); err != nil {
|
||||
return err
|
||||
}
|
||||
w.WriteString("]")
|
||||
case Mem:
|
||||
w.WriteString(fmt.Sprintf("M[%v]", inst.K))
|
||||
fmt.Fprintf(w, "M[%v]", inst.K)
|
||||
case Len:
|
||||
w.WriteString("len")
|
||||
default:
|
||||
@@ -120,13 +120,13 @@ func decodeLdx(inst Instruction, w *bytes.Buffer) error {
|
||||
|
||||
switch inst.OpCode & loadModeMask {
|
||||
case Imm:
|
||||
w.WriteString(fmt.Sprintf("%v", inst.K))
|
||||
fmt.Fprintf(w, "%v", inst.K)
|
||||
case Mem:
|
||||
w.WriteString(fmt.Sprintf("M[%v]", inst.K))
|
||||
fmt.Fprintf(w, "M[%v]", inst.K)
|
||||
case Len:
|
||||
w.WriteString("len")
|
||||
case Msh:
|
||||
w.WriteString(fmt.Sprintf("4*(P[%v:1]&0xf)", inst.K))
|
||||
fmt.Fprintf(w, "4*(P[%v:1]&0xf)", inst.K)
|
||||
default:
|
||||
return fmt.Errorf("invalid BPF LDX instruction: %v", linux.BPFInstruction(inst))
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func decodeAlu(inst Instruction, w *bytes.Buffer) error {
|
||||
func decodeSource(inst Instruction, w *bytes.Buffer) error {
|
||||
switch inst.OpCode & srcAluJmpMask {
|
||||
case K:
|
||||
w.WriteString(fmt.Sprintf("%v", inst.K))
|
||||
fmt.Fprintf(w, "%v", inst.K)
|
||||
case X:
|
||||
w.WriteString("X")
|
||||
default:
|
||||
@@ -205,10 +205,9 @@ func decodeJmp(inst Instruction, line int, w *bytes.Buffer) error {
|
||||
if err := decodeSource(inst, w); err != nil {
|
||||
return err
|
||||
}
|
||||
w.WriteString(
|
||||
fmt.Sprintf(") ? %s : %s",
|
||||
printJmpTarget(uint32(inst.JumpIfTrue), line),
|
||||
printJmpTarget(uint32(inst.JumpIfFalse), line)))
|
||||
fmt.Fprintf(w, ") ? %s : %s",
|
||||
printJmpTarget(uint32(inst.JumpIfTrue), line),
|
||||
printJmpTarget(uint32(inst.JumpIfFalse), line))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -227,7 +226,7 @@ func decodeRet(inst Instruction, w *bytes.Buffer) error {
|
||||
code := inst.OpCode & srcRetMask
|
||||
switch code {
|
||||
case K:
|
||||
w.WriteString(fmt.Sprintf("%v", inst.K))
|
||||
fmt.Fprintf(w, "%v", inst.K)
|
||||
case A:
|
||||
w.WriteString("A")
|
||||
default:
|
||||
|
||||
+5
-5
@@ -2036,26 +2036,26 @@ func (n *node) String() string {
|
||||
func (n *node) writeDebugString(buf *bytes.Buffer, prefix string) {
|
||||
if n.hasChildren != (n.nrSegments > 0 && n.children[0] != nil) {
|
||||
buf.WriteString(prefix)
|
||||
buf.WriteString(fmt.Sprintf("WARNING: inconsistent value of hasChildren: got %v, want %v\n", n.hasChildren, !n.hasChildren))
|
||||
fmt.Fprintf(buf, "WARNING: inconsistent value of hasChildren: got %v, want %v\n", n.hasChildren, !n.hasChildren)
|
||||
}
|
||||
for i := 0; i < n.nrSegments; i++ {
|
||||
if child := n.children[i]; child != nil {
|
||||
cprefix := fmt.Sprintf("%s- % 3d ", prefix, i)
|
||||
if child.parent != n || child.parentIndex != i {
|
||||
buf.WriteString(cprefix)
|
||||
buf.WriteString(fmt.Sprintf("WARNING: inconsistent linkage to parent: got (%p, %d), want (%p, %d)\n", child.parent, child.parentIndex, n, i))
|
||||
fmt.Fprintf(buf, "WARNING: inconsistent linkage to parent: got (%p, %d), want (%p, %d)\n", child.parent, child.parentIndex, n, i)
|
||||
}
|
||||
child.writeDebugString(buf, fmt.Sprintf("%s- % 3d ", prefix, i))
|
||||
}
|
||||
buf.WriteString(prefix)
|
||||
if n.hasChildren {
|
||||
if trackGaps != 0 {
|
||||
buf.WriteString(fmt.Sprintf("- % 3d: %v => %v, maxGap: %d\n", i, n.keys[i], n.values[i], n.maxGap.Get()))
|
||||
fmt.Fprintf(buf, "- % 3d: %v => %v, maxGap: %d\n", i, n.keys[i], n.values[i], n.maxGap.Get())
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf("- % 3d: %v => %v\n", i, n.keys[i], n.values[i]))
|
||||
fmt.Fprintf(buf, "- % 3d: %v => %v\n", i, n.keys[i], n.values[i])
|
||||
}
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf("- % 3d: %v => %v\n", i, n.keys[i], n.values[i]))
|
||||
fmt.Fprintf(buf, "- % 3d: %v => %v\n", i, n.keys[i], n.values[i])
|
||||
}
|
||||
}
|
||||
if child := n.children[n.nrSegments]; child != nil {
|
||||
|
||||
@@ -266,7 +266,7 @@ func (d *tcpRecoveryData) Generate(ctx context.Context, buf *bytes.Buffer) error
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = buf.WriteString(fmt.Sprintf("%d\n", recovery))
|
||||
_, err = fmt.Fprintf(buf, "%d\n", recovery)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func (d *tcpMemData) Generate(ctx context.Context, buf *bytes.Buffer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = buf.WriteString(fmt.Sprintf("%d\t%d\t%d\n", size.Min, size.Default, size.Max))
|
||||
_, err = fmt.Fprintf(buf, "%d\t%d\t%d\n", size.Min, size.Default, size.Max)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -393,10 +393,8 @@ func (q *Queue) Generate(ctx context.Context, buf *bytes.Buffer) error {
|
||||
// TODO: add method and sigNumber when mq_notify(2) is implemented.
|
||||
}
|
||||
|
||||
buf.WriteString(
|
||||
fmt.Sprintf("QSIZE:%-10d NOTIFY:%-5d SIGNO:%-5d NOTIFY_PID:%-6d\n",
|
||||
q.byteCount, method, sigNumber, pid),
|
||||
)
|
||||
fmt.Fprintf(buf, "QSIZE:%-10d NOTIFY:%-5d SIGNO:%-5d NOTIFY_PID:%-6d\n",
|
||||
q.byteCount, method, sigNumber, pid)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func (d *DriverSourceDir) GetUVMIncludePaths() []string {
|
||||
func WriteIncludeFile(sources []string, w io.Writer, ioctls []nvproxy.IoctlName) error {
|
||||
bufW := bufio.NewWriter(w)
|
||||
for _, source := range sources {
|
||||
if _, err := bufW.WriteString(fmt.Sprintf("#include \"%s\"\n", source)); err != nil {
|
||||
if _, err := fmt.Fprintf(bufW, "#include \"%s\"\n", source); err != nil {
|
||||
return fmt.Errorf("failed to write to include file: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func WriteIncludeFile(sources []string, w io.Writer, ioctls []nvproxy.IoctlName)
|
||||
// in the source file, we create constants with name "GVISOR_<ioctl_name>"
|
||||
// which are initialized with the ioctl macro.
|
||||
for _, ioctl := range ioctls {
|
||||
if _, err := bufW.WriteString(fmt.Sprintf("const uint64_t GVISOR_%s = %s;\n", ioctl, ioctl)); err != nil {
|
||||
if _, err := fmt.Fprintf(bufW, "const uint64_t GVISOR_%s = %s;\n", ioctl, ioctl); err != nil {
|
||||
return fmt.Errorf("failed to write to include file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user