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

x/text: unreachable code or out of bound in internal/number/decimal.go #42147

Closed
novinova opened this issue Oct 22, 2020 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@novinova
Copy link

novinova commented Oct 22, 2020

What version of Go are you using (go version)?

$ go version 1.14.

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Doesn't mean.

go env Output
$ go env

What did you do?

Looked through source code. And got one question.
Is this code correct in internal/number/decimal.go:385?

if scale > len(scales) { 
         mult = math.Pow(10, float64(scale))
} else {
         mult = scales[scale] //out of bound, isn't it?
}

Is else branch unreachable or there is some trick with go slices?

@gopherbot gopherbot added this to the Unreleased milestone Oct 22, 2020
@ianlancetaylor ianlancetaylor changed the title x/text unreachable code or out of bound in internal/number/decimal.go x/text: unreachable code or out of bound in internal/number/decimal.go Oct 22, 2020
@ianlancetaylor
Copy link
Contributor

CC @mpvl

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 22, 2020
@gopherbot
Copy link

Change https://golang.org/cl/265021 mentions this issue: internal/number: possible out of range error avoiding

@golang golang locked and limited conversation to collaborators Nov 25, 2021
xhit pushed a commit to xhit/text that referenced this issue Oct 10, 2022
Case when r.Increment > 0 and r.IncrementScale == len(scales) in *Decimal.ConvertFloat method is taken into account.
It led to unexpected out of range panic.

fixes golang/go#42147

Change-Id: Ic26e67010b766bdbd322a3853489f6d1ecb0dcfc
Reviewed-on: https://go-review.googlesource.com/c/text/+/265021
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Trust: Russ Cox <rsc@golang.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants