blob: bb1d13f3ff95bd88a81bc51282a892969ebd694a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <limits.h>
#include "triton.h"
#include "ipv6_dns.h"
#include "memdebug.h"
int __export ipv6_dns_reserve(struct ipv6_dns_t *dns, unsigned int count)
{
struct in6_addr *addr;
unsigned int capacity;
if (count <= dns->capacity)
return 0;
capacity = dns->capacity;
if (!capacity)
capacity = IPV6_DNS_INITIAL_CAPACITY;
while (capacity < count) {
/* Doubling past this would wrap around and spin forever */
if (capacity > UINT_MAX / 2)
return -1;
capacity *= 2;
}
addr = _realloc(dns->addr, capacity * sizeof(*addr));
if (!addr)
return -1;
dns->addr = addr;
dns->capacity = capacity;
return 0;
}
|