Skip to content

strconv: define integer return value in case of error in ParseInt #7105

@dominikh

Description

@dominikh
Usually, when a function returns an error, its other return values are considered
undefined. The current implementation of strconv.ParseInt, however, makes sure to return
meaningful values even in error cases. For format errors, it always returns 0 instead of
leaking parser state, and for overflow it returns the biggest/smallest possible value
and preserves the sign, as opposed to just wrapping around or behaving in other
unexpected ways.

These attributes can simplify code at the caller site, but only if they are documented
and guaranteed to stay in future versions and other implementations of the standard
library.

If they are in fact intended parts of the API, they should be documented as such.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions