summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-11-26 16:56:12 -0500
committerKyle Gunger <kgunger12@gmail.com>2023-11-26 16:56:12 -0500
commit3a5ec57cf8fe3bf10c81632dd5d6edaf959165be (patch)
treeb54b2f5c91949ce23e8df34628f5447aa182e4df
parente2c1a5b07de6260740bad4ed60b6035d94c441ae (diff)
Vector fixes
-rw-r--r--compiler.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler.c b/compiler.c
index de44994..de34038 100644
--- a/compiler.c
+++ b/compiler.c
@@ -53,7 +53,7 @@ bool vect_remove(Vector *v, size_t index) {
char *remove = v->data + (index * v->_el_sz);
char *override = v->data + (index + 1) * v->_el_sz;
- for(size_t i = 0; i < (v->count - 1) * v->_el_sz; i++) {
+ for(size_t i = 0; i < (v->count - index - 1) * v->_el_sz; i++) {
remove[i] = override[i];
}
@@ -79,11 +79,13 @@ bool vect_insert(Vector *v, size_t index, void *el) {
char *new_spot = v->data + (v->count + 1) * v->_el_sz;
char *old_spot = v->data + v->count * v->_el_sz;
- for (int i = ; i >= (index * v->_el_sz); i++) {
- new_spot[i] = old_spot[i];
+ for (size_t i = 0; i < (v->count - index) * v->_el_sz; i++) {
+ *new_spot = *old_spot;
+ new_spot--;
+ old_spot--;
}
- for (int i = 0; i < v->_el_sz; i++) {
+ for (size_t i = 0; i < v->_el_sz; i++) {
old_spot[i] = ((char *)el)[i];
}