Modulo By One

ID

go.modulo_by_one

Severity

low

Remediation Complexity

simple

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

CWE:1164, reliability, suspicious

Description

Reports a remainder expression x % 1. The remainder of any integer divided by 1 is always 0, so the entire expression is a constant zero.

Rationale

x % 1 can never be anything but 0, so writing it almost always signals a bug: a wrong divisor, a placeholder never filled in, or a constant that collapsed to one. The check fires only when the right-hand operand is the integer literal 1; a variable divisor or any other literal is left alone.

func fn(a int) {
    _ = a % 1 // FLAW — always zero
    _ = a % 2 // OK — meaningful remainder
}

Remediation

Use a meaningful divisor, or remove the remainder operation entirely if a constant zero was not intended.