Fix rvector assert when indexing empty ones ##r2r

* Crashing when passing corrupted tests to r2r
This commit is contained in:
pancake 2022-11-10 14:15:22 +01:00 committed by pancake
parent 12adbeedbe
commit 1a40fef85c
2 changed files with 4 additions and 0 deletions

View File

@ -237,6 +237,7 @@ R_API RPVector *r2r_load_cmd_test_file(const char *file) {
#undef DO_KEY_NUM
R_LOG_ERROR (LINEFMT ": Unknown key \"%s\"", file, linenum, line);
break;
} while ((line = nextline));
beach:
free (contents);

View File

@ -158,6 +158,9 @@ R_API void *r_vector_insert(RVector *vec, size_t index, void *x) {
R_API void *r_vector_insert_range(RVector *vec, size_t index, void *first, size_t count) {
r_return_val_if_fail (vec && index <= vec->len, NULL);
if (count < 1) {
return NULL;
}
if (vec->len + count > vec->capacity) {
RESIZE_OR_RETURN_NULL (R_MAX (NEXT_VECTOR_CAPACITY, vec->len + count));
}