Seek Whence Argument Order

ID

go.seek_whence_argument_order

Severity

high

Remediation Complexity

simple

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

CWE:683, reliability, suspicious

Description

Reports a Seek call whose arguments are swapped — the io.Seek* whence constant is passed in the first (offset) position.

Rationale

The io.Seeker interface declares Seek(offset int64, whence int), so the io.SeekStart / io.SeekCurrent / io.SeekEnd whence constant belongs in the second position. A call written as f.Seek(io.SeekStart, 0) passes the whence constant as the offset and a literal 0 as the whence, seeking to the wrong place. The rule fires on any two-argument Seek method call whose first argument is an io.Seek* constant.

import "io"

func fn(s io.Seeker) {
    s.Seek(io.SeekStart, 0) // FLAW — offset and whence swapped
    s.Seek(0, io.SeekStart) // OK
}

Remediation

Pass the offset first and the whence constant second: f.Seek(0, io.SeekStart).