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

call string.Repeat always with positive int #7104

Merged
merged 2 commits into from
Aug 25, 2021

Conversation

nonsense
Copy link
Member

@nonsense nonsense commented Aug 17, 2021

We have a report for a panic at:

panic: strings: negative Repeat count

goroutine 1 [running]:
strings.Repeat(0x37e2a10, 0x1, 0xffffffffffffffdf, 0x0, 0x0)
	/usr/local/go/src/strings/strings.go:529 +0x5e5
main.glob..func55(0xc000a51bc0, 0x0, 0x0)
	/home/reiers/lotus/cmd/lotus-miner/sealing.go:103 +0xa08
github.com/urfave/cli/v2.(*Command).Run(0x4c210a0, 0xc000a51ac0, 0x0, 0x0)
	/home/reiers/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:164 +0x4dd
github.com/urfave/cli/v2.(*App).RunAsSubcommand(0xc000702f00, 0xc000a518c0, 0x0, 0x0)
	/home/reiers/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:427 +0xa49
github.com/urfave/cli/v2.(*Command).startApp(0x4c21520, 0xc000a518c0, 0x7ffe9a138055, 0x7)
	/home/reiers/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:279 +0x6bb
github.com/urfave/cli/v2.(*Command).Run(0x4c21520, 0xc000a518c0, 0x0, 0x0)
	/home/reiers/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:94 +0x9cd
github.com/urfave/cli/v2.(*App).RunContext(0xc000702d80, 0x3863c10, 0xc000052948, 0xc00004e180, 0x3, 0x3, 0x0, 0x0)
	/home/reiers/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:306 +0x810
github.com/urfave/cli/v2.(*App).Run(...)
	/home/reiers/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:215
github.com/filecoin-project/lotus/cli.RunApp(0xc000702d80)
	/home/reiers/lotus/cli/helper.go:35 +0x7c
main.main()
	/home/reiers/lotus/cmd/lotus-miner/main.go:138 +0xd59

on tag m1.3.4


Apparently int(barCols)-ramBarsUsed-ramBarsRes somehow gets negative (calling it ramRepeatSpace now).

This PR is making sure ramRepeatSpace is set to 0, in case it is negative, and changes the colour of the string from yellow to red in this case.

@nonsense nonsense requested a review from magik6k August 17, 2021 12:09
@nonsense nonsense requested a review from a team as a code owner August 17, 2021 12:09
Comment on lines 106 to 110
if ramRepeatSpace < 0 {
ramRepeatSpace = 0
ramBar = color.RedString(strings.Repeat("|", ramBarsRes)) +
color.GreenString(strings.Repeat("|", ramBarsUsed)) +
strings.Repeat(" ", ramRepeatSpace)
} else {
ramBar = color.YellowString(strings.Repeat("|", ramBarsRes)) +
color.GreenString(strings.Repeat("|", ramBarsUsed)) +
strings.Repeat(" ", ramRepeatSpace)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: populate the variable portion of ramBar under the condition, then the static version outside.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

vmemBar := color.YellowString(strings.Repeat("|", vmemBarsRes)) +
color.GreenString(strings.Repeat("|", vmemBarsUsed)) +
strings.Repeat(" ", int(barCols)-vmemBarsUsed-vmemBarsRes)
strings.Repeat(" ", vmemRepeatSpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guaranteed to be non-negative?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure, so better be safe and keep the same pattern as ramBar for simplicity.

@Stebalien Stebalien marked this pull request as draft August 20, 2021 00:04
@nonsense nonsense force-pushed the nonsense/fix-repeat-string-negative branch from 398433e to 548865e Compare August 25, 2021 08:48
@nonsense nonsense marked this pull request as ready for review August 25, 2021 08:49
@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #7104 (548865e) into master (87fc8db) will decrease coverage by 0.05%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7104      +/-   ##
==========================================
- Coverage   34.85%   34.79%   -0.06%     
==========================================
  Files         685      685              
  Lines       80187    80197      +10     
==========================================
- Hits        27947    27908      -39     
- Misses      46553    46592      +39     
- Partials     5687     5697      +10     
Impacted Files Coverage Δ
cmd/lotus-miner/sealing.go 42.01% <57.14%> (-0.13%) ⬇️
journal/types.go 86.66% <0.00%> (-13.34%) ⬇️
extern/sector-storage/manager_calltracker.go 57.70% <0.00%> (-4.85%) ⬇️
chain/exchange/peer_tracker.go 66.66% <0.00%> (-4.31%) ⬇️
chain/stmgr/call.go 62.00% <0.00%> (-4.00%) ⬇️
node/hello/hello.go 63.21% <0.00%> (-3.45%) ⬇️
journal/fs.go 68.25% <0.00%> (-3.18%) ⬇️
chain/sub/incoming.go 49.70% <0.00%> (-2.37%) ⬇️
itests/kit/blockminer.go 93.65% <0.00%> (-1.59%) ⬇️
extern/storage-sealing/fsm.go 55.42% <0.00%> (-1.21%) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87fc8db...548865e. Read the comment docs.

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.

3 participants