Skip to content

x/crypto/openpgp: Strange loop in packet/packet.go #32474

@xiemaisi

Description

@xiemaisi

What version of Go are you using (go version)?

$ go version
go version go1.12.5 linux/amd64

Does this issue reproduce with the latest release?

N/A, this issue was found by a static analysis tool.

What operating system and processor architecture are you using (go env)?

Probably not important.

What did you do?

I noticed this strange-looking loop:

for power := uint(14); power < 32; power-- {
  // ...
}

Note that the loop variable power starts from 14 and is decremented in every iteration. The loop condition power < 32, on the other hand, bounds the variable upwards.

What did you expect?

If the present behaviour of counting power down from 14 to 0 and then terminating is correct, the loop condition should be replaced with power >= 0 to clarify this intention.

If the intention is to count from 14 up to 31, then power-- should be power++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions