Skip to content

False positive G115: integer overflow conversion rune -> byte #1636

@mholt

Description

@mholt

This code:

const maxByte = 255
asRunes := []rune(malformed)
final := make([]byte, len(asRunes))
for i, r := range asRunes {
	if r > maxByte {
		continue
	}
	final[i] = byte(r) // <-- FALSE POSITIVE? G115 here
}

produces a false positive on the marked line, I think.

Just above it, we skip that line if r > maxByte, and maxByte is const 255. So, it should never overflow right?

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