semgrep-go-correctness
Rules for finding odd Go code. See github.com/dgryski/semgrep-go to contribute.
Run Locally
Rules (68)

Odd use of anonymous structs for function arguments

Caret (^) is not exponentiation

Bad nil guard

QueryxContext rows must be closed (or use ExecContext)

Consider to use well-defined context

Use errors.Is($ERR, net.ErrClosed) instead

superfluous nil err check before return

TODO in error handling code

odd hash.Sum call flow

Comparing a MAC with bytes.Equal()

calling hmac.New with unchanging hash.New

use net.JoinHostPort instead of fmt.Sprintf($XX, $NET)

calling json.Encode() on an http.ResponseWriter will set Content-Type text/plain

use net/mail Address.String() instead of fmt.Sprintf()

MarshalJSON with a pointer receiver has surprising results: https://github.com/golang/go/issues/22967

Try using math/bits instead

return nil err instead of nil value

missing new relic end transaction

Odd bitwise expression

Odd comparison

Odd compound += or -= expression

Odd sequence of ifs

Odd bits.LeadingZeros() expression should perhaps be bits.Len()

New code should use errors.Is with the appropriate error type

64-bit integer parsed and downcast to u/int32

io.ReadFull() returns err == nil iff n == len(slice)

return nil instead of nil value

Maybe bad sort.Slice() less function

Use err.Error() instead

Leaky use of time.After in for-select, see: https://groups.google.com/g/golang-nuts/c/cCdm0Ixwi9A/m/jMiJJScAEAAJ

unless checking for wall clock inconsistencies, use !$T1.After($T2)

unless checking for wall clock inconsistencies, use !$T1.Before($T2)

use $W.Write($VAR) instead of io.WriteString when $VAR is []byte

maybe returning wrong error

Wrong lock/unlock pair?

did you want path.Join() or filepath.Join()?

it is good practice to call context cancellation function, $X(), in any case

ctx.Done() and time.After/time.NewTicker

old-style go-fuzz fuzz function found

passing an http-request scoped Context to a goroutine

ioutil.Discard is deprecated

ioutil.NopCloser is deprecated

ioutil.ReadAll is deprecated

ioutil.ReadDir is deprecated

ioutil.ReadFile is deprecated

ioutil.TempDir is deprecated

ioutil.TempFile is deprecated

ioutil.WriteFile is deprecated

Misspelling of MarshalJSON.

Misspelling of UnmarshalJSON.

Misspelling of MarshalYAML.

Misspelling of UnmarshalYAML.

return nil err instead of nil value

Odd comparison

Odd comparison

Odd comparison

Odd comparison

Odd comparison

Odd comparison

Odd comparison

Odd comparison

New code should use errors.Is with the appropriate error type

New code should use errors.Is with the appropriate error type

New code should use errors.Is with the appropriate error type

New code should use errors.Is with the appropriate error type

Read() can return n bytes and io.EOF

use fmt.Fprintf($W, $...VALS) instead of fmt.Sprintf and []byte conversion

use $W.Write($VAR) instead of fmt.Fprint when $VAR is []byte