-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
log: fix formatting of big.Int #22679
Conversation
The implementation of formatLogfmtBigInt had two issues: it crashed when the number was actually large enough to hit the big integer case, and modified the big.Int while formatting it.
Huh, I may have modified the code later. I did try those paths. |
log/format.go
Outdated
text := n.String() | ||
buf := make([]byte, 0, len(text)+len(text)/3) | ||
comma := 0 | ||
for _, c := range text { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to construct it backwards, otherwise you don't know where the commas need to be
=== RUN TestPrettyBigInt
format_test.go:76: invalid output 111,222,333,444,555,678,999,00, want 11,122,233,344,455,567,899,900
format_test.go:76: invalid output -111,222,333,444,555,678,999,00, want -11,122,233,344,455,567,899,900
s string | ||
}{ | ||
{"111222333444555678999", "111,222,333,444,555,678,999"}, | ||
{"-111222333444555678999", "-111,222,333,444,555,678,999"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add
{"11122233344455567899900", "11,122,233,344,455,567,899,900"},
{"-11122233344455567899900", "-11,122,233,344,455,567,899,900"},
the test will fail
* log: fix formatting of big.Int The implementation of formatLogfmtBigInt had two issues: it crashed when the number was actually large enough to hit the big integer case, and modified the big.Int while formatting it. * log: don't call FormatLogfmtInt64 for int16 * log: separate from decimals back, not front Co-authored-by: Péter Szilágyi <peterke@gmail.com>
The implementation of formatLogfmtBigInt had two issues: it crashed when
the number was actually large enough to hit the big integer case, and
modified the big.Int while formatting it.