diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c index 03186bfca808..120c12783feb 100644 --- a/lib/libarchive/archive_string.c +++ b/lib/libarchive/archive_string.c @@ -115,11 +115,11 @@ __archive_string_ensure(struct archive_string *as, size_t s) as->buffer_length = 32; else if (as->buffer_length < 8192) /* Buffers under 8k are doubled for speed. */ - as->buffer_length *= 2; + as->buffer_length += as->buffer_length; else { /* Buffers 8k and over grow by at least 25% each time. */ size_t old_length = as->buffer_length; - as->buffer_length = (as->buffer_length * 5) / 4; + as->buffer_length += as->buffer_length / 4; /* Be safe: If size wraps, release buffer and return NULL. */ if (as->buffer_length < old_length) { free(as->s); @@ -142,10 +142,12 @@ __archive_string_ensure(struct archive_string *as, size_t s) } struct archive_string * -__archive_strncat(struct archive_string *as, const char *p, size_t n) +__archive_strncat(struct archive_string *as, const void *_p, size_t n) { size_t s; - const char *pp; + const char *p, *pp; + + p = (const char *)_p; /* Like strlen(p), except won't examine positions beyond p[n]. */ s = 0; diff --git a/lib/libarchive/archive_string.h b/lib/libarchive/archive_string.h index 7960b8e07bb0..56ca7ca31805 100644 --- a/lib/libarchive/archive_string.h +++ b/lib/libarchive/archive_string.h @@ -99,8 +99,12 @@ __archive_string_ensure(struct archive_string *, size_t); #define archive_string_ensure __archive_string_ensure /* Append C string, which may lack trailing \0. */ +/* The source is declared void * here because this gets used with + * "signed char *", "unsigned char *" and "char *" arguments. + * Declaring it "char *" as with some of the other functions just + * leads to a lot of extra casts. */ struct archive_string * -__archive_strncat(struct archive_string *, const char *, size_t); +__archive_strncat(struct archive_string *, const void *, size_t); #define archive_strncat __archive_strncat /* Append a C string to an archive_string, resizing as necessary. */