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

BUG: Dividing Integers by Integers Leads to Incorrect Score Calculation #28

Closed
jspeed-meyers opened this issue Jan 17, 2023 · 1 comment · Fixed by #29
Closed

BUG: Dividing Integers by Integers Leads to Incorrect Score Calculation #28

jspeed-meyers opened this issue Jan 17, 2023 · 1 comment · Fixed by #29

Comments

@jspeed-meyers
Copy link
Contributor

In issue #22, it was pointed out that:

Package version score does not correspond to the % of package versions found? Am I misunderstanding what the correlation should be? If 97% have versions then shouldn't the package version score be higher?

After some testing, the bug seems to be here:

func (r *SpdxReport) PackageVersions() scorecard.ReportValue {
if r.totalPackages == 0 {
return scorecard.ReportValue{
Ratio: 0,
Reasoning: "No packages",
}
}
return scorecard.ReportValue{
Ratio: float32(r.hasPackVer / r.totalPackages),
}
}

Line 82 should be:

Ratio: float32(r.hasPackVer)  / float32(r.totalPackages),

Dividing an integer by an integer leads to zero, which is not the intended behavior, IIUC.

Here is a small snippet of Go code (in the Go Playground) explaining this bug: https://go.dev/play/p/gybFsSduxZa

Proposal: Fix all Ratio: lines to use the proper division in which both numbers are converted to a float32. This fix will encompass more than just the "package version" logic. I'm glad to put in a PR. Just LMK.

@justinabrahms
Copy link
Contributor

PR welcome, @jspeed-meyers. Thanks for the debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants