Skip to content

Lint about impossible condition #150

@extemporalgenome

Description

@extemporalgenome

@achille-roussel I'm eventually hoping to clean up a particular lint related to this code:

if v < math.MinInt64 || v > math.MaxInt64 {
	return r, unmarshalOverflow(b[:len(b)-len(r)], int32Type)
}

v in this case, is of type int64, thus the following lint seems accurate:

json/decode.go:453:6: SA4003: no value of type int64 is less than math.MinInt64 (staticcheck)

I can easily enough remove the entire branch, since it'd never evaluate anyways (and might even be eliminated during compilation), but the presence of the use of int32Type raises some questions:

  1. Should these be comparisons against MinInt32/MaxInt32?
  2. Is this code assuming that v is of type int32 (if not, why is int32Type being used)?
  3. What's the actual intended behavior? Since time.Duration's underlying type is int64, it would seem that decoder.parseInt should sufficiently cover any overflow checking need.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions