summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_string.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2007-07-15 19:13:59 +0000
committerkientzle <kientzle@FreeBSD.org>2007-07-15 19:13:59 +0000
commitc2571d8b749d2251abc1a93a11f2cf9c5b3d9cef (patch)
tree277b7c303ff4bb3a5583547383d51d714527e1c8 /lib/libarchive/archive_string.c
parent235eaa1de0144fe4b74f0955091911fb67fffa86 (diff)
downloadFreeBSD-src-c2571d8b749d2251abc1a93a11f2cf9c5b3d9cef.zip
FreeBSD-src-c2571d8b749d2251abc1a93a11f2cf9c5b3d9cef.tar.gz
archive_string_ensure() used to call exit(3) if it
couldn't allocate more memory for a string. Change this so it returns NULL in that case, and update all of its callers to handle the error. Some of those callers can now return errors back to the client instead of calling exit(3). Approved by: re (bmah)
Diffstat (limited to 'lib/libarchive/archive_string.c')
-rw-r--r--lib/libarchive/archive_string.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c
index b79c663..8e1d11c 100644
--- a/lib/libarchive/archive_string.c
+++ b/lib/libarchive/archive_string.c
@@ -44,7 +44,8 @@ __FBSDID("$FreeBSD$");
struct archive_string *
__archive_string_append(struct archive_string *as, const char *p, size_t s)
{
- __archive_string_ensure(as, as->length + s + 1);
+ if (__archive_string_ensure(as, as->length + s + 1) == NULL)
+ __archive_errx(1, "Out of memory");
memcpy(as->s + as->length, p, s);
as->s[as->length + s] = 0;
as->length += s;
@@ -54,7 +55,8 @@ __archive_string_append(struct archive_string *as, const char *p, size_t s)
void
__archive_string_copy(struct archive_string *dest, struct archive_string *src)
{
- __archive_string_ensure(dest, src->length + 1);
+ if (__archive_string_ensure(dest, src->length + 1) == NULL)
+ __archive_errx(1, "Out of memory");
memcpy(dest->s, src->s, src->length);
dest->length = src->length;
dest->s[dest->length] = 0;
@@ -69,6 +71,7 @@ __archive_string_free(struct archive_string *as)
free(as->s);
}
+/* Returns NULL on any allocation failure. */
struct archive_string *
__archive_string_ensure(struct archive_string *as, size_t s)
{
@@ -80,10 +83,8 @@ __archive_string_ensure(struct archive_string *as, size_t s)
while (as->buffer_length < s)
as->buffer_length *= 2;
as->s = (char *)realloc(as->s, as->buffer_length);
- /* TODO: Return null instead and fix up all of our callers to
- * handle this correctly. */
if (as->s == NULL)
- __archive_errx(1, "Out of memory");
+ return (NULL);
return (as);
}
OpenPOWER on IntegriCloud