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

Change Sequence index type to std::size_t #390

Open
drslebedev opened this issue Aug 8, 2024 · 0 comments
Open

Change Sequence index type to std::size_t #390

drslebedev opened this issue Aug 8, 2024 · 0 comments

Comments

@drslebedev
Copy link
Contributor

Currently, the Sequence class uses the type alias using signed_index_type = std::make_signed_t<std::size_t>; to represent indices. This choice can potentially lead to undefined behavior because of overflows, converting between signed and unsigned types, especially with large values, can result in incorrect indexing and arithmetic errors.

We should replace the signed index type with an unsigned

using index_type = std::size_t;

Additionally, we need to implement overflow protection to handle scenarios where the sequence index might wrap around its maximum value. In a CircularBuffer implementation, it is assumed that:

sequence + 1 > sequence

To maintain this invariant, we should introduce overflow checks and handle them appropriately to prevent undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Selected (3)
Development

No branches or pull requests

2 participants