Browse code

fix linting issues

Some false positives from gosec (G602: slice index out of range)

integration-cli/daemon/daemon.go:109:1: deprecatedComment: `Deprecated: ` notices should be in a dedicated paragraph, separated from the rest (gocritic)
// Deprecated: use cli.WaitCmd instead
^
integration-cli/docker_cli_build_test.go:562:3: dupOption: function argument `build.WithFile("test_file3", "test3")` is duplicated (gocritic)
build.WithFile("test_file3", "test3"),
^
integration-cli/docker_utils_test.go:250:1: deprecatedComment: `Deprecated: ` notices should be in a dedicated paragraph, separated from the rest (gocritic)
// Deprecated: use cli.WaitFor
^
daemon/libnetwork/ipams/defaultipam/address_space.go:45:39: G602: slice index out of range (gosec)
if predefined[j].Overlaps(predefined[i].Base) {
^
daemon/libnetwork/ipams/defaultipam/address_space.go:49:29: G602: slice index out of range (gosec)
predefined[j] = predefined[i]
^
daemon/libnetwork/libnetwork_linux_test.go:1492:9: G602: slice index out of range (gosec)
sboxes[thd-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", thd))
^
daemon/libnetwork/networkdb/cluster_test.go:111:21: G602: slice index out of range (gosec)
mean, stdev := nf[0], nf[1]
^
daemon/libnetwork/osl/interface_linux.go:586:54: G602: slice index out of range (gosec)
log.G(ctx).WithField("portState", stateFileContent[0]).Debug("waiting for bridge port to be forwarding")
^
daemon/libnetwork/osl/interface_linux.go:594:32: G602: slice index out of range (gosec)
"portState": stateFileContent[0],
^
daemon/libnetwork/portallocator/osallocator_linux_test.go:358:13: G602: slice index out of range (gosec)
if payload[0] != 0x1 {
^
daemon/libnetwork/portallocator/osallocator_linux_test.go:359:68: G602: slice index out of range (gosec)
readCh <- fmt.Errorf("expected payload 0x1, but got %x", payload[0])
^
daemon/logger/gelf/gelf_test.go:197:9: nilness: impossible condition: nil != nil (govet)
if err != nil {
^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/12/10 21:40:44
Showing 5 changed files
... ...
@@ -193,7 +193,7 @@ func TestNewGELFUDPWriter(t *testing.T) {
193 193
 	if err != nil {
194 194
 		t.Fatal(err)
195 195
 	}
196
-	writer.Close()
196
+	err = writer.Close()
197 197
 	if err != nil {
198 198
 		t.Fatal(err)
199 199
 	}
... ...
@@ -106,6 +106,7 @@ func (d *Daemon) WaitRun(contID string) error {
106 106
 }
107 107
 
108 108
 // WaitInspectWithArgs waits for the specified expression to be equals to the specified expected string in the given time.
109
+//
109 110
 // Deprecated: use cli.WaitCmd instead
110 111
 func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time.Duration, arg ...string) error {
111 112
 	after := time.After(timeout)
... ...
@@ -560,8 +560,8 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
560 560
 		build.WithFile("test_file1", "test1"),
561 561
 		build.WithFile("test_file2", "test2"),
562 562
 		build.WithFile("test_file3", "test3"),
563
-		build.WithFile("test_file3", "test3"),
564
-		build.WithFile("test_file4", "test4")))
563
+		build.WithFile("test_file4", "test4"),
564
+	))
565 565
 }
566 566
 
567 567
 // These tests are mainly for user namespaces to verify that new directories
... ...
@@ -178,7 +178,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *testing.T) {
178 178
 
179 179
 	// wait test1 to stop
180 180
 	hostArgs := []string{"--host", s.d.Sock()}
181
-	err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...)
181
+	err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...) //nolint:staticcheck // TODO WaitInspectWithArgs is deprecated.
182 182
 	assert.NilError(c, err, "test1 should exit but not")
183 183
 
184 184
 	// record last start time
... ...
@@ -189,7 +189,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *testing.T) {
189 189
 	s.d.Restart(c)
190 190
 
191 191
 	// test1 shouldn't restart at all
192
-	err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...)
192
+	err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...) //nolint:staticcheck // TODO WaitInspectWithArgs is deprecated.
193 193
 	assert.NilError(c, err, "test1 should exit but not")
194 194
 
195 195
 	// make sure test1 isn't restarted when daemon restart
... ...
@@ -247,6 +247,7 @@ func appendBaseEnv(isTLS bool, env ...string) []string {
247 247
 // waitInspect will wait for the specified container to have the specified string
248 248
 // in the inspect output. It will wait until the specified timeout (in seconds)
249 249
 // is reached.
250
+//
250 251
 // Deprecated: use cli.WaitFor
251 252
 func waitInspect(name, expr, expected string, timeout time.Duration) error {
252 253
 	return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout)