From 22aea8ffa3dba016734d9bba7a64b5fcd482b76e Mon Sep 17 00:00:00 2001 From: Sean Quinn Date: Sat, 4 Nov 2023 10:07:12 -0700 Subject: [PATCH] push_back for preallocation, avoid possible out of bounds crash, closes #151 --- test/kvec_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/kvec_test.cc b/test/kvec_test.cc index 1015574e..a7fdbe65 100644 --- a/test/kvec_test.cc +++ b/test/kvec_test.cc @@ -54,7 +54,7 @@ int main() for (i = 0; i < M; ++i) { std::vector array; array.reserve(N); - for (j = 0; j < N; ++j) array[j] = j; + for (j = 0; j < N; ++j) array.push_back(j); } printf("C++ vector, preallocated: %.3f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);