Go

Go

Made by DeepSource
Found for loop instead of append SCC-S1011
Anti-pattern
Major
Autofix

There is no need to range over the slice and append elements one by one; instead, use append because it's clear, simple, and idiomatic.

Using bytes.Equal to compare two net.IP SCC-SA1021
Bug risk
Major
Autofix

A net.IP stores an IPv4 or IPv6 address as a slice of bytes. The length of the slice for an IPv4 address, however, can be either 4 or 16 bytes long, using different ways of representing IPv4 addresses.

The empty for loop (for {}) spins and can block the scheduler SCC-SA5002
Bug risk
Major

An empty loop is bad news in two cases: 1) The loop has no condition. In that case, it's just a loop that spins forever and as fast as it can, keeping a core busy.

Using an invalid host:port pair with net.Listen SCC-SA1020
Bug risk
Major

Valid host:port pair should be of format hostname:n where n >= 0 && n <= 65535. Passing invalid host:port pair causes bug risk and potential security exposure.

Comparing a value against NaN even though no value is equal to NaN SCC-SA4012
Bug risk
Major

Generally, NaN is not considered equal to any number, including itself. That's because it represnts a number outside the range of representation.

Slice index out of bounds SCC-SA5006
Bug risk
Critical

A function that calls itself recursively needs to have an exit condition. Otherwise it will recurse forever, until the system runs out of memory.

Atomic access to 64-bit variable must be 64-bit aligned SCC-SA1027
Bug risk
Major

On ARM, x86-32, and 32-bit MIPS, the caller's responsibility is to arrange for 64-bit alignment of 64-bit words accessed atomically. The first word in a variable or an allocated struct, array, or slice can be relied upon to be

Called testing.T.FailNow or testing.T.SkipNow in a goroutine SCC-SA2002
Bug risk
Major

Calling t.Testing.FailNow or t.Testing.SkipNow in a goroutine isn't allowed.

Unreachable case clause in a type switch SCC-SA4020
Bug risk
Major

Beware of unreachable case clause in a type switch.

for { select { ... } } with an empty default branch spins SCC-SA5004
Bug risk
Major
Autofix

If you put an empty default: case in the select, it makes it non-blocking, which means that when no communication can proceed it executes the default case and, being empty, finishes immediately. Then the for { } loop runs the select

Found time.Now().Sub(t) instead of time.Since(t) SCC-S1012
Anti-pattern
Major
Autofix

The time.Since(t) helper has the same effect as using time.Now().Sub(t).

The finalizer references the finalized object, preventing garbage collection SCC-SA5005
Bug risk
Major

A finalizer is a function associated with an object that runs when the garbage collector is ready to collect said object, that is when the object is no longer referenced by anything.

If the finalizer references the object, however, it will always remain as the final reference to that object, preventing the garbage collector from collecting the object. The finalizer will never run, and the object will never be collected, leading to a memory leak. That is why the finalizer should instead use its first argument to operate on the object. That way, the number of references can temporarily go to zero before the object is being passed to the finalizer.

Invalid UTF-8 value provided SCC-SA1011
Bug risk
Major

Various methods in the strings package expect valid UTF-8, but invalid input is provided.

Invalid template SCC-SA1001
Bug risk
Critical

Issue is raised when templates cannot be parsed by the Parse function of html/template or text/template. For example, {{.Name}} {{.LastName} can not be parsed and causes runtime errors.

Bitwise operations, such as x ^ 0, do not do anything useful SCC-SA4016
Bug risk
Major
Autofix

Bitwise operations like x ^ 0 don't do anything.

strings.Replace/ bytes.Replace called with n == 0, which does nothing SCC-SA1018
Bug risk
Major
Autofix

With n == 0, zero instances will be replaced. To replace all instances, use a negative number, or use strings.ReplaceAll/ bytes.ReplaceAll.

It is not possible to use time.Timer.Reset()'s return value correctly SCC-SA1025
Bug risk
Critical

It is not possible to use Reset's return value correctly, as there is a race condition between draining the channel and the new timer expiring. Reset should always be invoked on stopped or expired channels. The return value exists to preserve compatibility with existing programs.

Comparing unsigned values against negative values is pointless SCC-SA4003
Bug risk
Major

Comparing unsigned values against negative values is pointless. This expression will always be true, because unsigned integers will never be less than zero.

The variable in the loop condition never changes SCC-SA4008
Bug risk
Critical

The value used in the loop condition never changes. In most cases, you might be incrementing the wrong variable.

Bind to all interfaces GSC-G102
Security
Major

Binding to all network interfaces can potentially open up a service to traffic on unintended interfaces.