summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/common.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-02-05 22:15:16 +0000
committerdes <des@FreeBSD.org>2002-02-05 22:15:16 +0000
commit36254aa73fc85e84a3d86f9988936692a6dacdb5 (patch)
tree23aad00f289210711038c8f1bc76c5051668b32f /lib/libfetch/common.c
parentec29926e4d7b6382c39d76ef0d75b6e476e13bfe (diff)
downloadFreeBSD-src-36254aa73fc85e84a3d86f9988936692a6dacdb5.zip
FreeBSD-src-36254aa73fc85e84a3d86f9988936692a6dacdb5.tar.gz
Switch to a self-starting allocation scheme.
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r--lib/libfetch/common.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index f2a1732..559c665 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -359,25 +359,18 @@ _fetch_add_entry(struct url_ent **p, int *size, int *len,
struct url_ent *tmp;
if (*p == NULL) {
-#define INITIAL_SIZE 8
- if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) {
- errno = ENOMEM;
- _fetch_syserr();
- return (-1);
- }
- *size = INITIAL_SIZE;
+ *size = 0;
*len = 0;
-#undef INITIAL_SIZE
}
if (*len >= *size - 1) {
- tmp = realloc(*p, *size * 2 * sizeof **p);
+ tmp = realloc(*p, (*size * 2 + 1) * sizeof **p);
if (tmp == NULL) {
errno = ENOMEM;
_fetch_syserr();
return (-1);
}
- *size *= 2;
+ *size = (*size * 2 + 1);
*p = tmp;
}
OpenPOWER on IntegriCloud