utils/cpio.c: Fix off-by-one error in cpio_vec_insert

Previously, if `cpio_vec_insert()` needed to replace a file and the file
already exists as the first entry, then a duplicate entry would get
created.

This fixes the bug I reported at:
https://forum.xda-developers.com/showpost.php?p=75449768&postcount=22647

Signed-off-by: Andrew Gunnerson <andrewgunnerson@gmail.com>
This commit is contained in:
Andrew Gunnerson 2018-02-07 21:14:42 -05:00 committed by topjohnwu
parent 5ad4702a5b
commit 70b7d73453

View File

@ -46,7 +46,7 @@ int cpio_cmp(const void *a, const void *b) {
void cpio_vec_insert(struct vector *v, cpio_entry *n) { void cpio_vec_insert(struct vector *v, cpio_entry *n) {
int i = cpio_find(v, n->filename); int i = cpio_find(v, n->filename);
if (i > 0) { if (i >= 0) {
// Replace, then all is done // Replace, then all is done
cpio_free(vec_entry(v)[i]); cpio_free(vec_entry(v)[i]);
vec_entry(v)[i] = n; vec_entry(v)[i] = n;