summaryrefslogtreecommitdiff
path: root/src/libsystemd-dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-dhcp')
-rw-r--r--src/libsystemd-dhcp/dhcp-client.c5
-rw-r--r--src/libsystemd-dhcp/test-dhcp-client.c1
2 files changed, 4 insertions, 2 deletions
diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c
index 9f7a826211..b9492a5a68 100644
--- a/src/libsystemd-dhcp/dhcp-client.c
+++ b/src/libsystemd-dhcp/dhcp-client.c
@@ -54,6 +54,7 @@ struct sd_dhcp_client {
union sockaddr_union link;
sd_event_source *receive_message;
uint8_t *req_opts;
+ size_t req_opts_allocated;
size_t req_opts_size;
be32_t last_addr;
struct ether_addr mac_addr;
@@ -115,11 +116,11 @@ int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option)
if (client->req_opts[i] == option)
return -EEXIST;
- if (!GREEDY_REALLOC(client->req_opts, client->req_opts_size,
+ if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated,
client->req_opts_size + 1))
return -ENOMEM;
- client->req_opts[client->req_opts_size - 1] = option;
+ client->req_opts[client->req_opts_size++] = option;
return 0;
}
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c
index 617236b5df..929b869ec3 100644
--- a/src/libsystemd-dhcp/test-dhcp-client.c
+++ b/src/libsystemd-dhcp/test-dhcp-client.c
@@ -85,6 +85,7 @@ static void test_request_basic(sd_event *e)
assert(sd_dhcp_client_set_request_option(client, 33) == 0);
assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
assert(sd_dhcp_client_set_request_option(client, 44) == 0);
+ assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
}
static uint16_t client_checksum(void *buf, int len)