Skip to content

G115 does not recognize overflow check conditions if the comparison order is different #1468

@etabegro

Description

@etabegro

Rule G115 warns if an integer overflow is not correctly checked before conversion. The check currently depends on the comparison order in the if statement:

This works:

if a < 0 || a > math.MaxUint8 {
    return nil, err
}

b := uint8(a)

This does not work (i.e. the rule will warn of a potential overflow):

if 0 > a  || a > math.MaxUint8 {
    return nil, err
}

b := uint8(a)

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