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.
This commit is contained in:
parent
f3675e5a86
commit
9838f0384d
@ -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;
|
||||
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user