diff options
author | kientzle <kientzle@FreeBSD.org> | 2009-04-12 04:59:11 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2009-04-12 04:59:11 +0000 |
commit | 9838f0384d4039f6eacc2a1b8e1aad8b881fc308 (patch) | |
tree | 4f13857de195e50d5d33562e5fbbec961f5a88a9 /lib/libarchive/archive_string.c | |
parent | f3675e5a869c16ce9a3aae04e94ac123001a50a6 (diff) | |
download | FreeBSD-src-9838f0384d4039f6eacc2a1b8e1aad8b881fc308.zip FreeBSD-src-9838f0384d4039f6eacc2a1b8e1aad8b881fc308.tar.gz |
Merge from libarchive.googlecode.com:
r751: Change __archive_strncat() to use a void * source, which reduces
the amount of casting needed to use this with "char", "signed char"
and "unsigned char".
r752: Use additions instead of multiplications when growing buffer;
faster and less chance of overflow.
Diffstat (limited to 'lib/libarchive/archive_string.c')
-rw-r--r-- | lib/libarchive/archive_string.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c index 03186bf..120c127 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; |