attractivechaos / klib

A standalone and lightweight C library
http://attractivechaos.github.io/klib/
MIT License
4.18k stars 556 forks source link

Potential crash: std::vector::resize and std::vector::reserve #151

Open Fr3ya opened 3 years ago

Fr3ya commented 3 years ago

This issue lies in the test/kvec_test.cc line 57

The function of resize() and reserve() is a little similar, but reserve() only gives to enough room so that future call that leads to increase of the size (e.g. calling push_back()) will be more efficient. So maybe line57 as follows is better: for (j = 0; j < N; ++j) array.push_back(j);