Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow package reports a false negative for 0 quotient #3326

Open
mvertes opened this issue Dec 11, 2024 · 0 comments
Open

Overflow package reports a false negative for 0 quotient #3326

mvertes opened this issue Dec 11, 2024 · 0 comments
Assignees
Labels
🐞 bug Something isn't working in focus Core team is prioritizing this work 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@mvertes
Copy link
Contributor

mvertes commented Dec 11, 2024

The following Go program:

package main

import "github.com/gnolang/gno/tm2/pkg/overflow"

func main() {
    var a, b int = -5, 7
    q, r, ok := overflow.Quotient(a, b)
    println(q, r, ok)
}

Gives the result 0 -5 false instead of 0 -5 true. An overflow is reported but it shouldn't be.

This affects all variants of Quotient function for signed integers: Quotient, Quotient8, Quotient16, Quotient32 and Quotient64. These functions are used for division / and remainder % operators.

The bug only affects results where the quotient is 0, all the other cases are correct. Note: in the overflow package, the test suite deliberately skipped the case where quotient is 0.

The issue is also present in https://github.com/gnolang/overflow and https://github.com/JohnCGriffin/overflow.

A fix is provided in #3250, precisely at

status := (c < 0) == ((a < 0) != (b < 0)) || (c == 0) // no sign check for 0 quotient

@mvertes mvertes added 🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related in focus Core team is prioritizing this work labels Dec 11, 2024
@mvertes mvertes self-assigned this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working in focus Core team is prioritizing this work 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Triage
Development

No branches or pull requests

1 participant