Skip to content
This repository was archived by the owner on Mar 18, 2021. It is now read-only.

Return value of MaxBigInt and family may change unexpectedly #4

Description

@keep94

big.Int instances are mutable. Which means that if a caller calls math.MaxBigInt(a, b) and later changes a or b, then what math.MaxBigInt returned could change unexpectedly

Consider the following code

a := big.NewInt(3)
b := big.NewInt(5)
c := math.MaxBigInt(a, b)  // c = 5, c and b point to the same big.Int
b.SetInt64(2)
// Oops, now c = 2, not 5. Caller won't be expecting this.

Although it would be slower, consider having math.MaxBigInt() and similar functions return a copy of the max value rather than the actual max value.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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