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 potential infinite loop in string_builder and list #23

Merged
merged 3 commits into from
Jun 7, 2024

Conversation

lenawanel
Copy link
Contributor

this would happen if the minimum length requested by the _grow_by
function was the highest power of 2 a usize could store.
So i.e. if a usize was 8bits of length you could have:

new_cap = 1;
while new_cap <= `0b10000000` {
	new_cap = new_cap << 1; // the highest new_cap can reach here is
				// 0b10000000 since anything higher overflows to 0
				// thus never not satisfying the loop condition and infinitely looping
}

lenawanel and others added 2 commits June 7, 2024 19:16
this would happen if the minimum length requested by the `_grow_by`
function was the highest power of 2 a `usize` could store.
So i.e. if a usize was 8bits of length you could have:
```c
new_cap = 1;
while new_cap <= `0b10000000` {
	new_cap = new_cap << 1; // the highest new_cap can reach here is
				// 0b10000000 since anything higher overflows to 0
				// thus never not satisfying the condition and infinitely looping
}
```
@lenawanel lenawanel marked this pull request as draft June 7, 2024 17:41
@lenawanel lenawanel marked this pull request as ready for review June 7, 2024 17:48
@NotAFlyingGoose NotAFlyingGoose merged commit 76bd90f into capy-language:master Jun 7, 2024
3 checks passed
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