summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-02-10 21:15:21 +0100
committerLennart Poettering <lennart@poettering.net>2015-02-10 21:15:21 +0100
commitb762fbd128480426d225596b18604a45042339c5 (patch)
tree3134df8741573f0c24aeea5e6f882a7e9fe2e366 /src
parent2e1a569b77f656500317cf2ca2382e9222ceab2f (diff)
test-lldp: use strndup() where possible
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/test-lldp.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c
index 2e6bf14e81..946f358e32 100644
--- a/src/libsystemd-network/test-lldp.c
+++ b/src/libsystemd-network/test-lldp.c
@@ -143,9 +143,8 @@ static int lldp_parse_port_id_tlv(tlv_packet *m) {
case LLDP_PORT_SUBTYPE_INTERFACE_NAME:
assert_se(tlv_packet_read_string(m, &str, &length) >= 0);
- p = malloc0(length + 1);
+ p = strndup(str, length-1);
assert_se(p);
- strncpy(p, str, length-1);
assert_se(streq(p, TEST_LLDP_PORT) == 1);
break;
@@ -165,9 +164,8 @@ static int lldp_parse_system_name_tlv(tlv_packet *m) {
assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_NAME) >= 0);
assert_se(tlv_packet_read_string(m, &str, &length) >= 0);
- p = malloc0(length + 1);
+ p = strndup(str, length);
assert_se(p);
- strncpy(p, str, length);
assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_NAME) == 1);
@@ -183,9 +181,8 @@ static int lldp_parse_system_desc_tlv(tlv_packet *m) {
assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_DESCRIPTION) >= 0);
assert_se(tlv_packet_read_string(m, &str, &length) >= 0);
- p = malloc0(length + 1);
+ p = strndup(str, length);
assert_se(p);
- strncpy(p, str, length);
assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_DESC) == 1);