Date: Sun, 12 Apr 2009 04:59:11 +0000 (UTC) From: Tim Kientzle <kientzle@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r190956 - head/lib/libarchive Message-ID: <200904120459.n3C4xB6D011182@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kientzle Date: Sun Apr 12 04:59:11 2009 New Revision: 190956 URL: http://svn.freebsd.org/changeset/base/190956 Log: 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. Modified: head/lib/libarchive/archive_string.c head/lib/libarchive/archive_string.h Modified: head/lib/libarchive/archive_string.c ============================================================================== --- head/lib/libarchive/archive_string.c Sun Apr 12 04:45:40 2009 (r190955) +++ head/lib/libarchive/archive_string.c Sun Apr 12 04:59:11 2009 (r190956) @@ -115,11 +115,11 @@ __archive_string_ensure(struct archive_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_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; Modified: head/lib/libarchive/archive_string.h ============================================================================== --- head/lib/libarchive/archive_string.h Sun Apr 12 04:45:40 2009 (r190955) +++ head/lib/libarchive/archive_string.h Sun Apr 12 04:59:11 2009 (r190956) @@ -99,8 +99,12 @@ __archive_string_ensure(struct archive_s #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. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904120459.n3C4xB6D011182>