diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2023-11-26 16:56:12 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2023-11-26 16:56:12 -0500 |
commit | 3a5ec57cf8fe3bf10c81632dd5d6edaf959165be (patch) | |
tree | b54b2f5c91949ce23e8df34628f5447aa182e4df | |
parent | e2c1a5b07de6260740bad4ed60b6035d94c441ae (diff) |
Vector fixes
-rw-r--r-- | compiler.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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]; } |