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 infinite loop #1367

Merged
merged 1 commit into from Feb 24, 2021
Merged

fix infinite loop #1367

merged 1 commit into from Feb 24, 2021

Conversation

bheni
Copy link
Contributor

@bheni bheni commented Feb 24, 2021

if length = length * 2 overflowed before it was greater than the necessary size ensureCapacity would loop forever. After 2 gigs we allocate a half gig at a time and if the allocation size exceeds a uint32 we panic, rather than fail later.

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

LG, just one comment

panic("overflow")
}

for minLength > length {
Copy link
Member

Choose a reason for hiding this comment

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

These loops seem like a strange way to ensure that length is bigger than minLength up to MaxUint32. Can't we just round up to the nearest half gig that's over the requested capacity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the bit twiddling approach to rounding to the next power of 2 isn't readable, and this isn't happening in a tight loop where this needs to be super fast so leaving the doubling loop.

If you a good way to round to the next half gig that works, feel free to suggest it. But I don't think it's more readable, and perf isn't a concern.

@bheni bheni merged commit 1dcc398 into master Feb 24, 2021
@bheni bheni deleted the bh/inf-loop-fix branch February 24, 2021 21:11
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.

None yet

2 participants