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

fix: correctly print disk sizes on 32bit systems #800

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

jooola
Copy link
Member

@jooola jooola commented Jun 28, 2024

The order of when the casting occurs is important, or we might overflow.

The bug can be reproduced with:

GOARCH=386 go test  ./...

@jooola jooola requested a review from a team as a code owner June 28, 2024 14:39
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 59.75%. Comparing base (12354bb) to head (4992347).

Files Patch % Lines
internal/cmd/server/describe.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #800   +/-   ##
=======================================
  Coverage   59.75%   59.75%           
=======================================
  Files         210      210           
  Lines        7598     7598           
=======================================
  Hits         4540     4540           
  Misses       2419     2419           
  Partials      639      639           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The order of when the casting occurs is important.

Can be reproduced with:
```
GOARCH=386 go test  ./...
```
@jooola jooola force-pushed the fix-32bits-system-size-handling branch from bff4095 to 4992347 Compare June 28, 2024 14:43
@jooola
Copy link
Member Author

jooola commented Jun 28, 2024

Found while updating the hcloud alpine package: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/68362

@jooola
Copy link
Member Author

jooola commented Jun 28, 2024

package main

import (
	"fmt"

	"github.com/dustin/go-humanize"
)

func main() {
	size := int(10)

	fail := uint64(size * humanize.GByte)
	happy := uint64(size) * humanize.GByte

	fmt.Printf("fail: %v\n", fail)
	fmt.Printf("fail: %s\n", humanize.Bytes(fail))

	fmt.Printf("happy: %v\n", happy)
	fmt.Printf("happy: %v\n", humanize.Bytes(happy))
}
$ go run ./main.go
fail: 10000000000
fail: 10 GB
happy: 10000000000
happy: 10 GB

$ GOARCH=386 go run ./main.go
fail: 1410065408
fail: 1.4 GB
happy: 10000000000
happy: 10 GB

@jooola jooola merged commit 3de8530 into main Jul 1, 2024
5 checks passed
@jooola jooola deleted the fix-32bits-system-size-handling branch July 1, 2024 13:44
jooola pushed a commit that referenced this pull request Jul 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.44.2](v1.44.1...v1.44.2)
(2024-07-01)


### Bug Fixes

* correctly print disk sizes on 32bit systems
([#800](#800))
([3de8530](3de8530))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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 this pull request may close these issues.

2 participants