diff options
author | Tim Kientzle <kientzle@FreeBSD.org> | 2007-07-15 19:13:59 +0000 |
---|---|---|
committer | Tim Kientzle <kientzle@FreeBSD.org> | 2007-07-15 19:13:59 +0000 |
commit | d3bb69751364bfe5fe7ad915646d5b327df9cb8b (patch) | |
tree | 277b7c303ff4bb3a5583547383d51d714527e1c8 /lib/libarchive/archive_string.c | |
parent | 75d0856ca5bd3d33a6a3627d58bd1a3fd73b3a0c (diff) |
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)
Notes
Notes:
svn path=/head/; revision=171460
Diffstat (limited to 'lib/libarchive/archive_string.c')
-rw-r--r-- | lib/libarchive/archive_string.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c index b79c6637ab18..8e1d11cb818c 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); } |