This commit is contained in:
blueloveTH 2024-12-14 00:40:14 +08:00
parent 98c38f2b1f
commit 79cdd2b252
2 changed files with 6 additions and 1 deletions

View File

@ -30,7 +30,8 @@ c11_vector c11_vector__copy(const c11_vector* self){
void c11_vector__reserve(c11_vector* self, int capacity){
if(capacity < 4) capacity = 4;
if(capacity <= self->capacity) return;
self->data = realloc(self->data, self->elem_size * capacity);
// self->elem_size * capacity may overflow
self->data = realloc(self->data, self->elem_size * (size_t)capacity);
self->capacity = capacity;
}

View File

@ -25,3 +25,7 @@ def gen_data():
for i in range(100):
ratio = test(gen_data())
# print(f'compression ratio: {ratio:.2f}')
# test 100MB of random data
rnd = [random.randint(0, 255) for _ in range(1024*1024*100)]
test(bytes(rnd))