mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 17:52:43 +00:00
Switch to a self-starting allocation scheme.
This commit is contained in:
parent
e19e6098b3
commit
5a51c23be3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90268
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user