Commit 70b7d734 authored by Andrew Gunnerson's avatar Andrew Gunnerson Committed by topjohnwu

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=22647Signed-off-by: 's avatarAndrew Gunnerson <andrewgunnerson@gmail.com>
parent 5ad4702a
...@@ -46,7 +46,7 @@ int cpio_cmp(const void *a, const void *b) { ...@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment