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:
Tim Kientzle 2009-04-12 04:59:11 +00:00
parent 0da7a22640
commit f8c35626c4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=190956
2 changed files with 11 additions and 5 deletions

View file

@ -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;

View file

@ -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. */