From 8a5405629f7dcbc2504ac55f57775180a011b846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Sun, 7 Nov 2021 00:59:26 +0300 Subject: Fixes and improvements * Fix heap corruption on buffer growth. * Define as static functions that are not used outside a TU. * Other minor changes. --- src/vector.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/vector.h') diff --git a/src/vector.h b/src/vector.h index 0a7c297..8df3af1 100644 --- a/src/vector.h +++ b/src/vector.h @@ -1,17 +1,21 @@ #ifndef UNJA_VECTOR_H #define UNJA_VECTOR_H -#include +#include + +#ifndef VECTOR_GROW_RATE +#define VECTOR_GROW_RATE 2 +#endif struct vector { void **values; - int size; - int cap; + size_t size; + size_t cap; }; -struct vector* vector_new(int cap); +struct vector *vector_new(size_t cap); -int vector_push(struct vector *vec, void *value); +size_t vector_push(struct vector *vec, void *value); void vector_free(struct vector *vec); -- cgit v1.2.3