aboutsummaryrefslogtreecommitdiff
path: root/src/vector.h
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-07 00:59:26 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-07 00:59:26 +0300
commit8a5405629f7dcbc2504ac55f57775180a011b846 (patch)
treed5009f3bce187a92386148b633b59787d6499244 /src/vector.h
parent33bdfde2be7e1c568d5e12ad1b27b7023dbd1b1b (diff)
downloadunja-8a5405629f7dcbc2504ac55f57775180a011b846.tar.gz
unja-8a5405629f7dcbc2504ac55f57775180a011b846.zip
Fixes and improvements
* Fix heap corruption on buffer growth. * Define as static functions that are not used outside a TU. * Other minor changes.
Diffstat (limited to 'src/vector.h')
-rw-r--r--src/vector.h14
1 files changed, 9 insertions, 5 deletions
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 <stdlib.h>
+#include <sys/types.h>
+
+#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);