shared/n-dhcp4: avoid c_min() macro to work with old GCC

This is required for the CI to pass, as CentOS has a too old version
of GCC. Ideally this patch should be dropped.
This commit is contained in:
Tom Gundersen
2019-05-31 16:28:15 +02:00
committed by Beniamino Galvani
parent 6adade6f21
commit d797611df5
2 changed files with 13 additions and 4 deletions

View File

@@ -183,7 +183,11 @@ _c_public_ void n_dhcp4_client_config_set_request_broadcast(NDhcp4ClientConfig *
*/ */
_c_public_ void n_dhcp4_client_config_set_mac(NDhcp4ClientConfig *config, const uint8_t *mac, size_t n_mac) { _c_public_ void n_dhcp4_client_config_set_mac(NDhcp4ClientConfig *config, const uint8_t *mac, size_t n_mac) {
config->n_mac = n_mac; config->n_mac = n_mac;
memcpy(config->mac, mac, c_min(n_mac, sizeof(config->mac)));
if (n_mac > sizeof(config->mac))
n_mac = sizeof(config->mac);
memcpy(config->mac, mac, n_mac);
} }
/** /**
@@ -209,7 +213,11 @@ _c_public_ void n_dhcp4_client_config_set_mac(NDhcp4ClientConfig *config, const
*/ */
_c_public_ void n_dhcp4_client_config_set_broadcast_mac(NDhcp4ClientConfig *config, const uint8_t *mac, size_t n_mac) { _c_public_ void n_dhcp4_client_config_set_broadcast_mac(NDhcp4ClientConfig *config, const uint8_t *mac, size_t n_mac) {
config->n_broadcast_mac = n_mac; config->n_broadcast_mac = n_mac;
memcpy(config->broadcast_mac, mac, c_min(n_mac, sizeof(config->broadcast_mac)));
if (n_mac > sizeof(config->mac))
n_mac = sizeof(config->mac);
memcpy(config->broadcast_mac, mac, n_mac);
} }
/** /**

View File

@@ -220,8 +220,9 @@ int n_dhcp4_outgoing_append(NDhcp4Outgoing *outgoing,
/* try fitting into allowed OPTIONs space */ /* try fitting into allowed OPTIONs space */
if (outgoing->max_size - outgoing->i_message >= n_data + 2U + 3U + 1U) { if (outgoing->max_size - outgoing->i_message >= n_data + 2U + 3U + 1U) {
/* try over-allocation to reduce allocation pressure */ /* try over-allocation to reduce allocation pressure */
n = c_min(outgoing->max_size, n = outgoing->n_message + n_data + 128;
outgoing->n_message + n_data + 128); if (n > outgoing->max_size)
n = outgoing->max_size;
m = realloc(outgoing->message, n); m = realloc(outgoing->message, n);
if (!m) if (!m)
return -ENOMEM; return -ENOMEM;