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

push_back for preallocation, avoid possible out of bounds crash #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seanpquinn
Copy link

closes #151

@@ -54,7 +54,7 @@ int main()
for (i = 0; i < M; ++i) {
std::vector<int> array;
array.reserve(N);
for (j = 0; j < N; ++j) array[j] = j;
for (j = 0; j < N; ++j) array.push_back(j);
Copy link

Choose a reason for hiding this comment

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

It seems that push_back here is useless, because array.reserve already reserves the space.

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.

Potential crash: std::vector::resize and std::vector::reserve
2 participants