3 ms·
AFAIK when the array is created, p->size should be set to 0, not to the size argument.
by antirez 10y ago
AFAIK when the array is created, p->size should be set to 0, not to the size argument.
- AlexeyBrin 10y agoThis mimics C++ vector, e.g.: vector<int> vec(5); vec.push_back(11); vec.push_back(12); Now you have in vec: 0, 0, 0, 0, 0, 11, 12 But your suggestion is better from an API point of view.
- antirez 10y agoOh... thanks! I was not aware.
- antirez 10y agoPS please note that there is no memset nor any other mean to zero initialize the elements. So the code appears to have a bug anyway.
- AlexeyBrin 10y agoCorrect, this is a bug. calloc will better mimic the way C++ std::vector works.